Mongoose 4.x "model.update ()" callback changed

Before mongoose 4.x in update (), you can check the second parameter in the callback to see if the document is found. In the example below, you can use "rowAffected" to find out if a document exists with the john username.

model.update({ username: "john" }, { ... }, function(err, rowAffected){ 
    if (rowAffected) // document found

But now from mongoose 4.x, the second parameter in the callback becomes the raw output of MongoDB from the update operation. So, to find if the file exists, I have to execute raw.n

model.update({ username: "john" }, { ... }, function(err, raw){ 
    if (raw.n) // document found

My question is: are "rowAffected" and "raw.n" the same ? If so, is it safe to replace all rowAffected raw.n when switching from 3.x to 4.x?

+4
source share
1 answer

, . 4.0:

# 2552: mongodb 2.0.x. Mongoose - MongoDB node. mongodb 2.0, . , Mongoose:

  • , replicaSet .
  • update MongoDB , . { ok: 1, n: 3 }, .
+3

All Articles