In Mysql, affect_rows can be used to view the number of rows affected in the database of this operation, but how to obtain this information in a text database? Or other debugging methods?
db.runCommand({getLastError: 1})
In output
getLastError.n
Parameters are affected records.Mongo Manual
It is defined as follows:n reports the number of documents updated or removed, if the preceding operation was an update or remove operation.
For example:
In onecollecton
There are two following records in{ "_id" : ObjectId("533e5cfa8d6728aef1f00111"), "sex" : "male" } { "_id" : ObjectId("533e5d088d6728aef1f00112"), "sex" : "female" }
First
run
Oneupdate
Operationdb.people.update({ "sex" : "male" }, { "sex" : "unknown"})
Again
run getLassError
Operationdb.runCommand({getLastError: 1})
The results are as follows:
{ "updatedExisting" : true, "n" : 1, "connectionId" : 1332, "err" : null, "ok" : 1 }
update
The operation affected 1 record, son
Is 1.
Againrun
Oneremove
Operationdb.people.remove()
The results are as follows:
{ "n" : 2, "connectionId" : 1332, "err" : null, "ok" : 1 }
remove
The operation affected 2 records, son
Two. At this time"updatedExisting" : true
Did not appear in the results because this information is only available inupdate
Appears after the operation.