monSQLize provides three update methods. This page is the entry point for choosing the method and update payload shape:
| Method | Description | Aggregation pipeline support |
|---|---|---|
updateOne() |
Update a single matching document | Supported |
updateMany() |
Update all matching documents | Supported |
updateBatch() |
Update a large number of documents in batches | Supported |
Current update methods support both traditional update operators and aggregation pipeline syntax. For the full pipeline guide, see Aggregation Pipeline Update Guide.
await users.updateOne(
{ userId: 'user1' },
{ $set: { name: 'Alice', age: 25 } }
);await users.updateOne(
{ userId: 'user1' },
{ $unset: { tempField: '' } }
);await users.updateOne(
{ userId: 'user1' },
{ $inc: { loginCount: 1, balance: -100 } }
);await users.updateOne(
{ userId: 'user1' },
{ $push: { tags: 'newTag' } }
);await users.updateOne(
{ userId: 'user1' },
{ $pull: { tags: 'oldTag' } }
);await users.updateOne(
{ userId: 'user1' },
{
$set: { status: 'active' },
$inc: { loginCount: 1 },
$push: { loginHistory: new Date() }
}
);Use an aggregation pipeline when the update needs to reference existing field values, run conditional logic, or perform multi-stage transformations. The update payload is an array of pipeline stages:
await orders.updateOne(
{ orderId: 'ORDER-123' },
[
{ $set: { total: { $add: ['$price', '$tax'] } } }
]
);This overview intentionally stops at selection and basic syntax. See Aggregation Pipeline Update Guide for supported stages, operator examples, performance notes, and troubleshooting.
| Need | Recommended shape | Where to continue |
|---|---|---|
| Simple assignment or field removal | Traditional operators such as $set / $unset |
updateOne() / updateMany() |
| Numeric increment or array push/pull | Traditional operators such as $inc, $push, $pull |
updateOne() / updateMany() |
| Field-to-field calculation | Aggregation pipeline array | Aggregation Pipeline Update Guide |
| Conditional assignment or multi-stage transformation | Aggregation pipeline array | Aggregation Pipeline Update Guide |
| Large update workload | updateBatch() with either payload shape |
Batch update |