MongoDB Last Error 命令
getlasterror是验证最后一次连接数据库操作。可以通过以下几种方式来进行调用:
> db.$cmd.findOne({getlasterror:1})或者
> db.runCommand("getlasterror")或者用shell辅助方法
> db.getLastError()
更多的命令查看?command documentation.
驱动各个驱动都支持?getlasterror??以及许多还提供了"safe"模式的操作。如果你使用Python,你可以使用如下语句来自动调用getlasterror。?
collection.save({"name": "MongoDB"}, safe=True)如果保存失败,异常就会抛出。关于"safe"模式,详情请看各个驱动的文档。
注意: ?mongo wire protocol?killCursors 操作不支持 getlasterror.? (如果你是 驱动?developers一定要注意?.)
参数fsync> db.runCommand({getlasterror:1,fsync:true}){ "err" : null, "n" : 0, "fsyncFiles" : 2, "ok" : 1 }w写操作成功复制N个服务器之前,写操作都是阻塞状态。> db.getLastError(2, 5000) // w=2, timeout 5000ms