Daniel
Daniel

Reputation: 1582

MongoDB's save() - can be used with Update Operators like $set?

Can I use MongoDB's save() command with update operators like "$set"?

Or save() can be used to "update" - only while replacing all the fields (except the ID)?

Upvotes: 1

Views: 83

Answers (1)

Asya Kamsky
Asya Kamsky

Reputation: 42352

No, you cannot.

$set is an operator of an update statement. Save is syntactic sugar that will insert a document or overwrite an existing document with entire new document.

You are likely looking for an update operation with upsert option set to true with $set and possibly also $setOnInsert operators.

Upvotes: 1

Related Questions