我是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