I have a record in my collection and I want to fetch the details of the person whose id is 1. But I am getting the details for 2times instead of 1.
db.mycollection.insert({"person" : [ { "id":1, "details" : { "name" : "Aswini", "Age" : 10 }}, { "id":2, "details" : { "name" : "Mahesh", "Age" : 11}}]})
Then running
> db.mycollection.findOne({"person.id":1},{"person.details":1,"_id":0})
the result is :
{
"person" :
[
{
"details" :
{
"name" : "Aswini",
"Age" : 10
}
},
{
"details" :
{
"name" : "Mahesh",
"Age" : 11
}
}
]
}
But I need as follows:
{
"person" : [
{
"details" : {
"name" : "Aswini",
"Age" : 10
}
}
]
}
Don't understand where am making mistake. Please need your help. Am using MongoDB, Java