I am moving from SQL over to MonboDB, and I am trying learn the basics. But so far I have struggled with one "Select statement"
Lets say I have this kind of collection
document 1
{
"_id" : "id1",
"name" : "aa",
"array" : [
{
"nested_id" : "n323123",
"nesteddata" : "lorem",
"active" : 1
},
{
"nested_id" : "n353123",
"nesteddata" : "lorem",
"active" : 0
},
{
"nested_id" : "n323123",
"nesteddata" : "lorem",
"active" : 1
}
]
}
document 2
{
"_id" : "id2",
"name" : "bb",
"array" : [
{
"nested_id" : "n325123",
"nesteddata" : "lorem",
"active" : 1
},
{
"nested_id" : "n355123",
"nesteddata" : "lorem",
"active" : 1
},
{
"nested_id" : "n323123",
"nesteddata" : "lorem",
"active" : 0
}
]
}
I then want to select one and ONLY the nested data. Have tried with the following statement without any success.
db.testing.findOne( {_id: "id1", "array.active" : 1} )
but I am still getting all the data without the filter