如何多维数组搜索值, 比如我想搜索在MongoDB中 以下数据example
关键字我用来从命令如何使用mongodb搜索内部数组中的字符串?
>db.info.find()
{
"_id" : ObjectId("4f74737cc3a51043d26f4b90"),
"id" : "12345",
"info" : [
{
"sno" : 1,
"name" : "ABC",
"email" : "[email protected]"
},
{
"sno" : 2,
"name" : "XYZ",
"email" : "[email protected]"
},
{
"sno" : 3,
"name" : "XYZ",
"email" : "[email protected]"
},
{
"sno" : 4,
"name" : "ABC",
"email" : "[email protected]"
},
{
"sno" : 5,
"name" : "Rohan",
"email" : "[email protected]"
}
]
}
获取所有数据现在,找到数据具有example
我用命令
>db.info.find({"info.email":"example"})
和它给
{
"_id" : ObjectId("4f74737cc3a51043d26f4b90"),
"id" : "12345",
"info" : [
{
"sno" : 1,
"name" : "ABC",
"email" : "[email protected]"
},
{
"sno" : 2,
"name" : "XYZ",
"email" : "[email protected]"
},
{
"sno" : 3,
"name" : "XYZ",
"email" : "[email protected]"
},
{
"sno" : 4,
"name" : "ABC",
"email" : "[email protected]"
},
{
"sno" : 5,
"name" : "Rohan",
"email" : "[email protected]"
}
]
}
但我想只有3个5个个子行像
{
"_id" : ObjectId("4f74737cc3a51043d26f4b90"),
"id" : "12345",
"info" : [
{
"sno" : 1,
"name" : "ABC",
"email" : "[email protected]"
},
{
"sno" : 2,
"name" : "XYZ",
"email" : "[email protected]"
},
{
"sno" : 5,
"name" : "Rohan",
"email" : "[email protected]"
}
]
}
它会给整个文档未搜索到的内阵列的数据。 – 2012-04-28 06:51:33