In mongodb, i wrote a query for fetching record which is having "xxx" value in the record. Below is my code:

let query = Business.aggregate([
  { "$match": { "events.kioskActivationId": kioskActivationId } },
  { "$unwind": "$events" }
]);

return query.exec();

My model for business is:

const schema = new Schema({
mobile:         {type: String, unique:true},
name:           {first:String, last:String},
password:       String,
email :         String,
session:        String,
events:         [{eventName: String, kioskActivationId: String, kiosks: [{kioskType: String, physicalId: String, sessionId: String}]}]
});

I wrote the code for fetching the business and event record. My input is kioskActivationId.

I got the output as:

Business record is:

{
    "_id": "5863acced0607e1c64a5748f",
    "mobile": "111",
    "password": "202cb962ac59075b964b07152d234b70",
    "events": {
        "eventName": "Test",
        "kioskActivationId": "846157",
        "_id": "5864086047cb452f3420337e",
        "kiosks": []
    },
    "__v": 6,
    "session": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJkYXRhIjoiNTg2M2FjY2VkMDYwN2UxYzY0YTU3NDhmIiwiaWF0IjoxNDgyOTI3MzEwLCJleHAiOjE0ODI5NDg5MTB9.921Lkd5AGJIAhorKYR7--tpHg2516CASmnFzpi9kO4E"
}

I have added a new record to kiosk as:

businessRecord.events.kiosks.push(kiosk);
businessRecord.save().then((updatedEvent) => {
    console.log("Updated event is: ",updatedEvent);
});

Here i am facing the issue,Unhandled rejection TypeError: businessRecord.save is not a function.

Can anyone provide the solution for this.

0

There are 0 best solutions below