I am very new in mongodb. I just start my project using mongodb.In my project i need to get the data from nested array. I know there are too many questions related to this, but my problem is not solved. here is json.
{
"_id": ObjectId("58805a04469d401ab45943f6"),
"siteId": 2,
"guardGender": "MALE",
"checkoutPoint": [{
"_id": ObjectId("588098a025bad12cf01936d6"),
"title": "string",
"nfcCheckoutPoint": [{
"_id": ObjectId("5880c14683d042207896f7a4"),
"title": "yup",
"intervalTime": "string",
}]
}]
}
I need only nfcCheckoutPoint array.
"nfcCheckoutPoint": [{
"_id": ObjectId("5880c14683d042207896f7a4"),
"title": "yup",
"intervalTime": "string",
}]
This is my code which i am using
var criteria = {
_id: payloadData.siteId,
"checkoutPoint._id": payloadData.routeId,
"checkoutPoint.nfcCheckoutPoint._id": payloadData.checkpointId
};
var projection = { nfcCheckoutPoint: { $elemMatch: { _id: payloadData.checkpointId }}}
var option = {
lean: true
};
Service.SiteService.getSite(criteria, projection, option, function (err, data) {
if (err) {
cb(err)
} else {
console.log(data)// this give me wrong values
}
})
var getSite = function (criteria, projection, options, callback) {
options.lean = true;
Models.Site.find(criteria, projection, options, callback);
};
With this code i am getting:
{ "_id": ObjectId("58805a04469d401ab45943f6")}
my problem is not solvedis too vague statement. What are you trying to solve? What is the problem you are facing? Have a look at How do I ask a good question?.getSite()?