下面是我的代碼commant db.slist.findOne()添加文件到嵌入式陣列
如何添加一個id與「INAME」爲「肥皂」後陣回來了? 我需要編寫一個查詢來蒐集集合中的所有「itemlist」數組,並且如果嵌入文檔中的任何文檔的「iname」爲「Soap」,則應在「iname:」Soap上方插入一個新行「Soap」作爲「項目Id」,並設置項目ID自己。有人能幫我找到了正確的查詢呢?
而且這似乎是一個很難回答的問題,請讓我知道,如果你發現很難理解的問題。
{
"_id" : ObjectId("5914213e9f75f9119575c1d7"),
"name" : "Athif",
"age" : 23,
"address" : {
"house" : "675/38B",
"street" : "West Hill",
"city" : "Chungam",
"pincode" : 676507
},
"itemlist" : [
{
"iname" : "Soap",
"quantity" : 2,
"price" : 10,
"rate" : 20
},
{
"iname" : "helmet",
"quantity" : 1,
"price" : 500,
"rate" : 500
},
{
"iname" : "Table",
"quantity" : 2,
"price" : 5000,
"rate" : 10000
}
]
}
在itemlist數組中可以有多個對象作爲「Soap」? – Shrabanee
查看鏈接http://stackoverflow.com/documentation/mongodb/1683/crud-operation/22368/update-of-embedded-documents#t=201705111314015170307。這將幫助你瞭解你能做什麼。 – Shrabanee