Answer the question
In order to leave comments, you need to log in
How to get data from nested JSON MongoDB object with nodeJS?
I have JSON object in MongoDB
I have tried
findOne({'menu.products':
{$elemMatch:{
'_id': 60475de5ce4dd6151019d574
}
}})
distinct('menu.products', { 'menu.products._id': 60475de5ce4dd6151019d574 })
Answer the question
In order to leave comments, you need to log in
There is no need to store data like this, this is an unnormalized base, it’s better to redo it before it’s too late.
In particular, products must be links to another data collection. Your problem arises precisely for this reason.
// api: collection.find{filter, options}
myCollection.find({
'menu.products': {
$in: {
{
'_id': 60475de5ce4dd6151019d574
}
}
}
}, {
projection: {
'menu.products': 1
}
})
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question