Mongoose update without callback

The right way to call update with mongoose is the following:

User.update(query, update).exec(callback);

This way you will be able to skip callback:

User.update(query, update).exec();

When you calls

User.update(query, update)

it returns a query object.

It’s very useful when you querying your database, because you can manipulate with query object before executing it. For example, you can specify a limit for your find query:

User.find(query).limit(12).exec(callback);

Update uses the same mechanism, though its not so useful there.

Leave a Comment