在 Mysql 中可用通过 affect_rows 来查看本次操作数据库中受影响的行数,但是在文本型数据库中怎么获取这些信息呢?Or 别的调试方式?
业精于勤,荒于嬉;行成于思,毁于随。
db.runCommand({getLastError: 1})
In the output getLastError.n 参数就是受影响的记录。Mongo Manual is defined like this:
getLastError.n
Mongo Manual
n reports the number of documents updated or removed, if the preceding operation was an update or remove operation.
Example: There are two following records in one collecton
collecton
{ "_id" : ObjectId("533e5cfa8d6728aef1f00111"), "sex" : "male" } { "_id" : ObjectId("533e5d088d6728aef1f00112"), "sex" : "female" }
operaterun 一个 update
run
update
db.people.update({ "sex" : "male" }, { "sex" : "unknown"})
againrun getLassError
run getLassError
{ "updatedExisting" : true, "n" : 1, "connectionId" : 1332, "err" : null, "ok" : 1 }
is 1. update 操作影响了 1 个记录,所以 n Then operaterun 一个 remove
n
remove
db.people.remove()
{ "n" : 2, "connectionId" : 1332, "err" : null, "ok" : 1 }
Appears after operation. remove 操作影响了 2 个记录,所以 n 为 2。此时 "updatedExisting" : true 未在结果中出现,因为该信息只在 update
"updatedExisting" : true
In the json returned by the
update statement, the value with key n is the number of modified rows. Print it out and see for yourself
In the output
getLastError.n
参数就是受影响的记录。Mongo Manual
is defined like this:Example:
FirstThere are two following records in one
collecton
operate
Operationrun
一个update
again
The results are as follows:run getLassError
is 1.
The results are as follows:update
操作影响了 1 个记录,所以n
Thenoperate
run
一个remove
Appears after operation.
remove
操作影响了 2 个记录,所以n
为 2。此时"updatedExisting" : true
未在结果中出现,因为该信息只在update
In the json returned by the
update statement, the value with key n is the number of modified rows.
Print it out and see for yourself