mongodb getLastError()php

mongodb getLastError()php,php,mongodb,getlasterror,Php,Mongodb,Getlasterror,如何在php中使用getLastError()检查save方法是否插入mongo 我按如下方式设置数据库: $this->databaseEngine = $app['mongo']; $this->db = $this->databaseEngine->dbname; $this->collection = $this->db->collectionname; 我的insert查询如下所示: $query = array( 'fieldnam

如何在php中使用getLastError()检查save方法是否插入mongo

我按如下方式设置数据库:

$this->databaseEngine = $app['mongo'];
$this->db = $this->databaseEngine->dbname;
$this->collection = $this->db->collectionname;
我的insert查询如下所示:

$query = array(
    'fieldname' => $fieldname
);
$this->collection->insert($query);
然后我想使用getLastError()检查它是否正确插入,如果没有,原因是什么。但我不知道如何实施它

插入后是否使用:

$this->collection->getLastError("what goes here?");
干杯

更新 我最终用这个来得到最后一个错误:

echo '<pre>' . print_r($this->databaseEngine->lastError(), true) . '</pre>';
echo“”。打印($this->databaseEngine->lastError(),true)。“”;
Sammaye的方法同样有效,见下文

$this->collection->getLastError(“这里是什么?”)

这里什么都没有,返回的
getLastError
是来自MongoDB()的最后一个错误。它也用于MongoDB类(atm)

您不必这样使用它,相反,您可以:

这将从函数返回一个数组,详细说明它是否实际插入。通过阅读此页面可以找到阵列的详细信息:

$this->collection->insert($query, ARRAY('safe' => TRUE));