【问题标题】:Why the delete() method of Phalcon\Mvc\Collection in the MongoDB collection may not work?为什么MongoDB集合中Phalcon\Mvc\Collection的delete()方法可能不起作用?
【发布时间】: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”的文档仍然存在。

【问题讨论】:

    标签: php mongodb phalcon


    【解决方案1】:

    问题出在集合的名称上。由于我将集合命名为大写,因此未删除该文档。我将集合的名称更改为“auto_sn-p”并且删除工作有效。

    【讨论】:

      猜你喜欢
      • 2016-02-25
      • 2021-08-02
      • 1970-01-01
      • 2011-10-21
      • 2017-09-18
      • 1970-01-01
      • 2022-01-15
      • 1970-01-01
      • 2017-05-08
      相关资源
      最近更新 更多