Skip to content

Commit bfe9cb6

Browse files
committed
update batcher - allow setting upsert:false
1 parent 41247a0 commit bfe9cb6

File tree

1 file changed

+10
-3
lines changed

1 file changed

+10
-3
lines changed

api/parts/data/batcher.js

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -232,7 +232,7 @@ class WriteBatcher {
232232
updateOne: {
233233
filter: {_id: this.data[db][collection][key].id},
234234
update: this.data[db][collection][key].value,
235-
upsert: true
235+
upsert: this.data[db][collection][key].upsert
236236
}
237237
});
238238
}
@@ -340,18 +340,25 @@ class WriteBatcher {
340340
* @param {string} id - id of the document
341341
* @param {object} operation - operation
342342
* @param {string} db - name of the database for which to write data
343+
* @param {object=} options - options for operation ((upsert: false) - if you don't want to upsert document)
343344
*/
344-
add(collection, id, operation, db = "countly") {
345+
add(collection, id, operation, db = "countly", options) {
345346
if (!this.shared || cluster.isMaster) {
346347
if (!this.data[db][collection]) {
347348
this.data[db][collection] = {};
348349
}
349350
if (!this.data[db][collection][id]) {
350-
this.data[db][collection][id] = {id: id, value: operation};
351+
this.data[db][collection][id] = {id: id, value: operation, upsert: true};
352+
if (options && options.upsert === false) {
353+
this.data[db][collection][id].upsert = false;
354+
}
351355
batcherStats.update_queued++;
352356
}
353357
else {
354358
this.data[db][collection][id].value = common.mergeQuery(this.data[db][collection][id].value, operation);
359+
if (options && options.upsert === false) {
360+
this.data[db][collection][id].upsert = this.data[db][collection][id].upsert || false;
361+
}
355362
}
356363
if (!this.process) {
357364
this.flush(db, collection);

0 commit comments

Comments
 (0)