Mohamed Elloumi
Mohamed Elloumi

Reputation: 158

failed: id is not defined while parsing unsing mongoose

So I am trying to parse some data using mongoose my schema looks like

data: [{

    'order-id': String,
    'sku': String,
    'purchase-date': String,
    'payments-date': String,

and I am trying to get the data using :

let parseddata = new ParsedDataModel(doc) ;
parseddata.data[0].order-id // failed id is not defined

While

parseddata.data[0].sku // is working

Is this a problem with the dash 6 ? How can I solve it ?

Upvotes: 0

Views: 29

Answers (1)

Dushyant Bangal
Dushyant Bangal

Reputation: 6403

The problem is with your "dash".

Node js thinks it is a "minus" and your id is another variable.

Try using the following:

parseddata.data[0]["order-id"]

PS: I would recommend using ObjectId as the type for order-id instead of String. You can then populate the order document directly from this itself.

Upvotes: 1

Related Questions