【发布时间】:2020-03-29 15:40:37
【问题描述】:
我在 mongoDb 集合中插入了三个文档。我想从集合中删除一个文档。:
是mongoDB模型:
use \Phalcon\Mvc\MongoCollection;
class AutoSnippet extends MongoCollection
{
public $name;
public $snippets = [];
public function onConstruct()
{
$this->setSource('AutoSnippet');
}
public function initialize()
{
$this->setConnectionService('mongodbTracker');
$this->getConnection()->selectCollection('AutoSnippet');
}
}
他们都成功了。
1)
$snippet = AutoSnippet::findById("5e80a9d2577d257fe9703314");
2)
$snippet = AutoSnippet::findFirst([[
'_id' => new MongoDB\BSON\ObjectID("5e80a9d2577d257fe9703314")
]]);
但 delete() 方法不起作用:
$snippet->delete(); // returns true
delete() 方法返回 true 但 ID 为“5e80a9d2577d257fe9703314”的文档仍然存在。
【问题讨论】: