我是mongoDB中的新成員,我看到了足夠多的示例,但大多數都展示瞭如何使用集合。如何從mongoDB中的對象獲取字段列表?
下DB名myDB
存儲在MongoDB中我按照數據:
"_id" : "some_table_name",
"content" : [{
"id" : "1",
"loctype" : "Clinic/Hospital",
"locname" : "KKH"
}, {
"id" : "2",
"loctype" : "Clinic/Hospital",
"locname" : "Singapore National Eye Centre"
}
}]
}
正如你所看到的模型包含_id
和content
,其中content
爲對象的名單:
... ,
{
"id" : "ZZZ",
"loctype" : "ZZZ",
"locname" : "ZZZ"
},
...
PHP
$m = new MongoClient(/* ... */);
$db = $m->myDB;
$collection = $db->coll;
如何獲取PHP的ID列表? a.e [1,2]
在我的情況。
當然,我可以得到所有模型和提取id,但我嘗試從mongoDB中直接做。
謝謝。
所以這是MongoDB的CLI的語法,對不對? –
@MaximShoustin True,轉換爲PHP – Sammaye
Downvoter,小心解釋一下? – Sammaye