0
我想重複使用PHP的MongoDB查詢。MongoDB的PHP查詢只返回子對象項目
以下查詢使用mongo shell工作。
db.user.find({"_id": ObjectId("52d1cedfb1c097b41800055e"), "address.type": "home"},
{"_id": 0, "address.coordinent.longitude": 1, "address.coordinent.latitude": 1, "address.zipcode": 1})
它返回:
{ "address" : [ { "zipcode" : "84123", "coordinent" : {
"longitude" : -111.908978, "latitude" : 40.63147499999999 } } ] }
我出現以下結果文件:
$db->user->findOne(array("_id" => $mongoID))
但使用PHP以下嘗試不起作用:
$db->user->findOne(array("_id" => $mongoID), array("address->type" => "home"},{"_id": 0, "address->coordinent->longitude" => 1, "address->coordinent->latitude" => 1, "address->zipcode" => 1}))
And:
$db->user->findOne(array("_id" => $mongoID), array("address[type]" => "home"},{"_id": 0, "address[coordinent][longitude]" => 1, "address[coordinent][latitude]" => 1, "address[zipcode]" => 1}))
在PHP中查詢的正確格式是什麼?