我的目標是搜索數據的用戶ID的記錄1MongoDB的多嵌套數組搜索
下面是我的數據
{ "_id" : 2,
"name" : "test",
"data" :[{"_id" : "1","file" : "nic", "userid" : [1,2 ]},
{"_id" : "2","file" : "nic1","userid" : [1 ] },
{"_id" : 3,"file" : "nick2","userid" : [1,2 ]}
]},
{ "_id" : 3,
"name" : "test",
"data" : [{"_id" : "1","file" : "nic","userid" : [1,2 ] },
{"_id" : "2","file" : "nic1", "userid" : [3,2 ] }
]}
出來放應
{ "_id" : 2,
"name" : "test",
"data" :[{"_id" : "1","file" : "nic", "userid" : [1,2 ]},
{"_id" : "2","file" : "nic1","userid" : [1 ] },
{"_id" : 3,"file" : "nick2","userid" : [1,2 ]}
]},
{ "_id" : 3,
"name" : "test",
"data" : [{"_id" : "1","file" : "nic","userid" : [1,2 ] },
]}
我試圖
$res=$collection->find(array("data.userid" =>array('$in'=>array('52'))));
返回null
收到錯誤'例外:無效操作「$ setDifference'' –
@sasikanth這意味着你有一個相當舊版本的MongoDB(2.6以上),它沒有那些運營商。有一個替代(而不是性能)的方法可以適用於所有版本。 MongoDB 2.6現在已經有幾年了,爲什麼要考慮升級有很多原因。 –
感謝您的幫助。我會更新我的版本並檢查一次。我需要一個更多的幫助。我想顯示數據中的所有記錄作爲循環我怎樣才能做到這一點 –