dman
dman

Reputation: 11064

Mongoose - Does where cause a extra query?

For MongoDB and Mongoose, does this cause 2 queries because of the where clause? Like findAndModify does because it returns the whole document before modifying?

Model.where({ _id: id }).update({ title: 'words' })

Upvotes: 1

Views: 20

Answers (1)

JohnnyHK
JohnnyHK

Reputation: 312035

Nope, but neither does findAndModify, as in both cases the entire command is executed atomically by the MongoDB server.

To confirm, you can see the commands that Mongoose is executing by adding the following to your code:

mongoose.set('debug', true);

Upvotes: 2

Related Questions