[{
"_id" : ObjectId("55f181e43fdda0be857daaf4"),
"form_info" : [
{
"val" : "王思聪",
"id" : "1"
},
{
"val" : "13800138000",
"id" : "2"
}
],
"tags" : [],
"__v" : 0
},
{
"_id" : ObjectId("55f181e43fdda0f48578acf4"),
"form_info" : [
{
"val" : "李丽珍",
"id" : "1"
},
{
"val" : "13934438010",
"id" : "2"
}
],
"tags" : [],
"__v" : 0
}]
如果我想筛选form_info
数组内符合 成员对象内id
为1,val
为王思聪
且id
为2,val
为13800138000
的记录。
即结果是:
[{
"_id" : ObjectId("55f181e43fdda0be857daaf4"),
"form_info" : [
{
"val" : "王思聪",
"id" : "1"
},
{
"val" : "13800138000",
"id" : "2"
}
],
"tags" : [],
"__v" : 0
}]
该怎么写好? 谢谢大大们
Can you take a look at how your record is stored in the database? This is it:
Or is each subdocument in the array an independent record? If it really works like what you showed above, then if you check _id directly, you will get the only record. If according to my understanding, then execute this query:
That’s it
I am learning mongodb and try to answer some questions on sf.
This is a query for mongodb’s embedded array. If the index is known, you can use numeric index query.
Use array index to match fields of embedded documents
So the query can be written like this: