I've the following document in MongoDB...
{
"_id" : ObjectId("531221cd960100960116b992"),
"username : "joe",
"address" : [
{
"zip" : "8000",
"city" : "Zurich"
},
{
"zip" : "6900",
"city" : "Lugano"
}
]
}
... and to retrieve the second address I use the following statement:
db.users.find({ _id: ObjectId("531221cd960100960116b992") }, { addresses: { $slice: [0, 1] } } )
This works except it also returns the object id:
{ "addresses" : [ { "zip" : "6900", "city" : "Lugano" } ], "_id" : ObjectId("531221cd960100960116b992") }
How do I prevent MongoDB from returning the object id? I know I should provide a projection like _id : 0
... but where should I put it in the expression above? I did a number of tries... but without success.
Thanks.