Skip to content
This repository has been archived by the owner on Oct 19, 2024. It is now read-only.

Latest commit

 

History

History
44 lines (34 loc) · 763 Bytes

update-api.md

File metadata and controls

44 lines (34 loc) · 763 Bytes

Update API

Supported update operators:

  • $inc
  • $mul
  • $rename
  • $set
  • $unset
  • $min
  • $max
  • $addToSet
  • $pop
  • $push
  • $pull
  • $pullAll
  • $slice
  • $sort

API:

collection.update(query, updates)

  • query is the same query object as in Query API.
  • updates is an object that contains updates and zero or more update operators

Returns a promise which resolves with a number of updated objects.

Examples:

Perform a simple field update:

db.collection('people').update({ lastname: 'Doe' }, { age: 45 }).then(function(updatesCount) {
    // ...
});

Perform an update using update operators:

db.collection('people').update({ lastname: 'Doe' }, { $inc: { age: 1 } }).then(function(updatesCount) {
    // ...
});