Update Methods Overview

1. Overview

monSQLize provides three update methods. This page is the entry point for choosing the method and update payload shape:

MethodDescriptionAggregation pipeline support
updateOne()Update a single matching documentSupported
updateMany()Update all matching documentsSupported
updateBatch()Update a large number of documents in batchesSupported

Current update methods support both traditional update operators and aggregation pipeline syntax. For the full pipeline guide, see Aggregation Pipeline Update Guide.


2. Traditional update operator

2.1 Common operators

$set - Set field value

await users.updateOne(
    { userId: 'user1' },
    { $set: { name: 'Alice', age: 25 } }
);

$unset - delete a field

await users.updateOne(
    { userId: 'user1' },
    { $unset: { tempField: '' } }
);

$inc - increase/decrease value

await users.updateOne(
    { userId: 'user1' },
    { $inc: { loginCount: 1, balance: -100 } }
);

$push - Add elements to an array

await users.updateOne(
    { userId: 'user1' },
    { $push: { tags: 'newTag' } }
);

$pull - remove elements from an array

await users.updateOne(
    { userId: 'user1' },
    { $pull: { tags: 'oldTag' } }
);

2.2 Combination use

await users.updateOne(
    { userId: 'user1' },
    {
        $set: { status: 'active' },
        $inc: { loginCount: 1 },
        $push: { loginHistory: new Date() }
    }
);

3. Aggregation pipeline handoff

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.

4. Choosing the update shape

NeedRecommended shapeWhere to continue
Simple assignment or field removalTraditional operators such as $set / $unsetupdateOne() / updateMany()
Numeric increment or array push/pullTraditional operators such as $inc, $push, $pullupdateOne() / updateMany()
Field-to-field calculationAggregation pipeline arrayAggregation Pipeline Update Guide
Conditional assignment or multi-stage transformationAggregation pipeline arrayAggregation Pipeline Update Guide
Large update workloadupdateBatch() with either payload shapeBatch update