首先,我想说我的英语不好,但我希望你能理解我的意思。
我有一个例子:
db.test
{
"_id" => 1337,
children => [
{
"_id" => ObjectID("527225eb0f7250c7cc76cbfa"),
Name => "Test",
},
{
"_id" => ObjectID("527227280f7250c7cc76cbfb"),
Name => "Abc",
}
]
},
{
"_id" => 0815,
children => [
{
"_id" => ObjectID("dkfjshfusfhdsdghs"),
Name => "Blabla",
}
]
}
现在我按姓名搜索孩子,我使用 db.test.findOne({“children.Name”:“Abc”)并获得以下结果:
{
"_id" : "1337",
"children" : [
{
"_id" : ObjectId("527225eb0f7250c7cc76cbfa"),
"Name" : "Test"
},
{
"_id" : ObjectId("527227280f7250c7cc76cbfb"),
"Name" : "Abc"
}
]
}
我的结果很好,他找到了“master”对象。但我想只得到像这样的子对象:
{
"_id" : ObjectId("527227280f7250c7cc76cbfb"),
"Name" : "Abc"
}
我怎样才能实现这一目标?