example
多次元配列で値を検索する方法、たとえば、コマンドからすべてのデータをフェッチするために使用したmongodbの次のデータでキーワードを検索したい
>db.info.find()
{
"_id" : ObjectId("4f74737cc3a51043d26f4b90"),
"id" : "12345",
"info" : [
{
"sno" : 1,
"name" : "ABC",
"email" : "abc@example.com"
},
{
"sno" : 2,
"name" : "XYZ",
"email" : "xyz@example.com"
},
{
"sno" : 3,
"name" : "XYZ",
"email" : "xyz@demo.com"
},
{
"sno" : 4,
"name" : "ABC",
"email" : "abc@demo.com"
},
{
"sno" : 5,
"name" : "Rohan",
"email" : "rohan@example.com"
}
]
}
example
今、私がコマンドを使用したデータを見つけるために
>db.info.find({"info.email":"example"})
そしてそれは与える
{
"_id" : ObjectId("4f74737cc3a51043d26f4b90"),
"id" : "12345",
"info" : [
{
"sno" : 1,
"name" : "ABC",
"email" : "abc@example.com"
},
{
"sno" : 2,
"name" : "XYZ",
"email" : "xyz@example.com"
},
{
"sno" : 3,
"name" : "XYZ",
"email" : "xyz@demo.com"
},
{
"sno" : 4,
"name" : "ABC",
"email" : "abc@demo.com"
},
{
"sno" : 5,
"name" : "Rohan",
"email" : "rohan@example.com"
}
]
}
しかし、私は次のような5つのサブ行のうち3つだけが必要です
{
"_id" : ObjectId("4f74737cc3a51043d26f4b90"),
"id" : "12345",
"info" : [
{
"sno" : 1,
"name" : "ABC",
"email" : "abc@example.com"
},
{
"sno" : 2,
"name" : "XYZ",
"email" : "xyz@example.com"
},
{
"sno" : 5,
"name" : "Rohan",
"email" : "rohan@example.com"
}
]
}