Skip to content

Latest commit

 

History

History
31 lines (26 loc) · 556 Bytes

File metadata and controls

31 lines (26 loc) · 556 Bytes

Demo for Merge

Example of code

import {AggregateBuilder, WhenMatched} from 'mongodb-aggregate-builder';

const aggBuilder = new AggregateBuilder();
aggBuilder.merge(
    "updated_collection",
    "_id",
    WhenMatched.REPLACE,
    WhenNotMatched.INSERT
);
console.log(JSON.stringify(aggBuilder.build(), null, 2));

Result

[
    {
        "$merge": {
            "into": "updated_collection",
            "on": "_id",
            "whenMatched": "replace",
            "whenNotMatched": "insert"
        }
    }
]