i have this collection in mongodb :
db.persons.find().pretty();{
"_id" : ObjectId("564635a944ae32e021f8b81b"),
"items" : [
{
"_id" : ObjectId("564635a944ae32e021f8b819"),
"personId" : 1,
"first_name" : "A",
"last_name" : "B",
"gender" : "m",
"comment" : "123"
},
{
"_id" : ObjectId("564635a944ae32e021f8b81a"),
"personId" : 2,
"first_name" : "w",
"last_name" : "X",
"gender" : "m",
"comment" : "987"
}
]},{
"_id" : ObjectId("564635a944ae32e021f8b812"),
"items" : [
{
"_id" : ObjectId("564635a944ae32e021f8b8d5"),
"personId" : 3,
"first_name" : "Y",
"last_name" : "Z",
"gender" : "f",
"comment" : "357"
}]}
with this command(findOne) :
> db.persons.findOne({"items.personId" : 1})
get this result :
{
"_id" : ObjectId("564635a944ae32e021f8b81b"),
"items" : [
{
"_id" : ObjectId("564635a944ae32e021f8b819"),
"personId" : 1,
"first_name" : "A",
"last_name" : "B",
"gender" : "m",
"comment" : "123"
},
{
"_id" : ObjectId("564635a944ae32e021f8b81a"),
"personId" : 2,
"first_name" : "w",
"last_name" : "X",
"gender" : "m",
"comment" : "987"
}
]}
but; how I get this result : only first_name & last_name & _id from items that personId = 1
{
"_id" : ObjectId("564635a944ae32e021f8b819"),
"first_name" : "A",
"last_name" : "B"
}
(just with the findOne command(No aggregate)). very thanks...