[{
"_id" : ObjectId("55f181e43fdda0be857daaf4"),
"form_info" : [
{
"val": "Wang Sicong",
"id" : "1"
},
{
"val" : "13800138000",
"id" : "2"
}
],
"tags" : [],
"__v" : 0
},
{
"_id" : ObjectId("55f181e43fdda0f48578acf4"),
"form_info" : [
{
"val": "Li Lizhen",
"id" : "1"
},
{
"val" : "13934438010",
"id" : "2"
}
],
"tags" : [],
"__v" : 0
}]
If I want to screenform_info
Within the array matches within the member objectid
Is 1,val
ForSicong Wang
Andid
Is 2,val
For13800138000
A record of.
The result is:
[{
"_id" : ObjectId("55f181e43fdda0be857daaf4"),
"form_info" : [
{
"val": "Wang Sicong",
"id" : "1"
},
{
"val" : "13800138000",
"id" : "2"
}
],
"tags" : [],
"__v" : 0
}]
How to write it? Thank you very much
Can you look at how this record of yours is stored in the database? Here’s the thing:
db.test6.insert( {"test":[{ "_id" : ObjectId("55f181e43fdda0be857daaf4"), "form_info" : [ { "val": "Wang Sicong", "id" : "1" }, { "val" : "13800138000", "id" : "2" } ], "tags" : [], "__v" : 0 }, { "_id" : ObjectId("55f181e43fdda0f48578acf4"), "form_info" : [ { "val": "Li Lizhen", "id" : "1" }, { "val" : "13934438010", "id" : "2" } ], "tags" : [], "__v" : 0 }]})
Or is each subdocument in the array an independent record? If this is the case as shown above, then you can check the ID directly and take out the unique record. If as I understand it, then execute this query:
> db.test6.find({"test._id":ObjectId("55f181e43fdda0be857daaf4")},{"test.$":1}).pretty(); { "_id" : ObjectId("55f255aef566c6baf2af1fac"), "test" : [ { "_id" : ObjectId("55f181e43fdda0be857daaf4"), "form_info" : [ { "val": "Wang Sicong", "id" : "1" }, { "val" : "13800138000", "id" : "2" } ], "tags" : [ ], "__v" : 0 } ] }
I wish I could