Suppose you have a structure like
a: {
b: [
{
c: 1,
d: 2
},
{
c: 3,
d: 4
}
]
}
Now search for d=4 and display only the c value i.e 3 in this case. The code is
db.users.aggregate([
{$match : { _id:ObjectId("5b8a7174e7f55107e694d323"),
"b.d": {$in : ['4']} } },
{$unwind : "$b" },
{$match : { "b.d" : "4" }},
{$project : { d : "$b.d", c: "$b.c",
_id:0
}} ]);
Some other quries
db.users.aggregate([
// Get just the docs that contain a shapes element where color is 'red'
{$match: {
_id: ObjectId("5b8a7174e7f55107e694d323"),
"referral_details.email": {$in : ['[email protected]']}
}},
{$project: {
referral_details: {$filter: {
input: '$referral_details',
as: 'referral_details',
cond: {$eq: ['$$referral_details.email', '[email protected]']}
}},
_id: 0
}}
]);
AND
db.users.find({
_id:ObjectId("5b8a7174e7f55107e694d323"),
"referral_details.email": {$in : ['[email protected]']}
},{"referral_details.referral_id.$":1});
hello bhaiya . Can U please tell me how to download amazons/coursekart videos. Please