updateMany
Updated at:
Updates multiple records in a collection.
Method signature
updateMany(filter: object, update: object, options?: object): Promise<MongoResult>Request parameters
Field name | Type | Required | Description |
|---|---|---|---|
| Object | Yes | The filter condition. |
| Object | Yes | The update document. |
| Object | No | Control |
The options parameter is described as follows:
Field name | Type | Required | Description |
|---|---|---|---|
| Boolean | No | Specifies whether to insert the document if no match is found. The default is |
Examples
Finds all records in the
userscollection where thenamefield is `jerry` and updates theiragefield to 10.mpserverless.db.collection('users').updateMany({ name: 'jerry' }, { $set: { age: 10 } }) .then(res => {}) .catch(console.error);Finds all records in the
userscollection where theagefield is greater than 18 and updates their `name` and `age` fields. Other fields remain unchanged. If no matching records are found, a new record{name: "Smith", age: 22}is inserted.mpserverless.db.collection('users').updateMany({ age: { $gt: 18 } }, { $set: { name: "Smith", age: 22 } }, { upsert: true }) .then(res => {}) .catch(console.error);
Is this page helpful?