我对PHP和MongoDB都很陌生。我想使用MongoDB文档的ObjectId删除它,但它似乎无法工作。
下面是添加对象的方式。因为我没有指定id,所以Mongo为我生成了一个。
public static function addUserPet($userPet) {
$m = new MongoClient();
$db = $m->petfinder;
$collection = $db->userpets;
$collection->insert($userPet);
echo json_encode($userPet);
}这里是我尝试更新对象的地方。我不明白如何使用ObjectId访问文档。
public static function deleteUserPet($userPet)
{
$m = new MongoClient();
$db = $m->petfinder;
$collection = $db->userpets;
$criteria = ???
$collection->remove($criteria, true);
}$criteria应该是什么?
注意:这是传入的对象。

发布于 2017-08-01 15:38:04
首先,必须获取集合,然后从特定集合中获取文档。请看一下:http://php.net/manual/en/mongocollection.findone.php
关于标准:
array('_id' => new MongoId('47cc67093475061e3d9536d2')https://stackoverflow.com/questions/45441791
复制相似问题