I don't think this is a duplicate, but please correct me if I'm wrong. Anyway, I would like to return only "apple" and the customer member role that matches the user's object email address. I am using $elemMatch, but that returns the whole customer object, I only want the "member" property, that's it.
{
"_id" : ObjectId("54d24e5df2878d40192beabd"),
"apple" : "yes",
"orange" : "yes",
"customers" : [
{
"name" : "Jay Smith",
"email" : "[email protected]",
"member" : "silver",
},
{
"name" : "Sarah Carter",
"email" : "[email protected]",
"member" : "gold",
},
{
"name" : "Jack Whatever",
"email" : "[email protected]",
"member" : "gold",
},
]
}
Ideal result back would be:
{
"_id" : ObjectId("54d24e5df2878d40192beabd"),
"apple" : "yes",
"member" : "gold"
}
or even this would suffice:
{
"_id" : ObjectId("54d24e5df2878d40192beabd"),
"apple" : "yes",
"orange" : "yes",
"customers" : [
{"member" : "gold"}
]
}
This is currently what I have:
ItemsModel.find({ _id: { $in: _.pluck(user.items, 'itemId') }, active: true},
{apple: 1, customers: {$elemMatch: {email: user.email}} },
function(error, items) {
if (error) { return next(error); }
req.payload = {};
req.payload.items = items;
next();
});
Any help would be really appreciated. Is this even possible? Thanks!