WriteBatcher

WriteBatcher

Class for batching database operations for aggregated data

Constructor

new WriteBatcher(db)

Source:

Create batcher instance

Example
let batcher = new WriteBatcher(common.db);
 batcher.set("eventsa8bb6a86cc8026768c0fbb8ed5689b386909ee5c", "no-segment_2020:0_2", {"$set":{"segments.name":true, "name.Runner":true}});
Parameters:
Name Type Description
db Db

database object

Methods

add(collection, id, operation, db)

Source:

Provide operation for document id and batcher will try to merge multiple operations

Parameters:
Name Type Default Description
collection string

name of the collection where to update data

id string

id of the document

operation object

operation

db string countly

name of the database for which to write data

addDb(name, connection)

Source:

Add another database to batch

Parameters:
Name Type Description
name string

name of the database

connection Db

MongoDB connection to that database

(async) flush(db, collection)

Source:

Writes data to database for specific collection

Parameters:
Name Type Description
db string

name of the database for which to write data

collection string

name of the collection for which to write data

flushAll() → {Promise}

Source:

Run all pending database queries

Returns:

promise

Type
Promise

get(collection, id, db) → {object}

Source:

Get operation on document by id

Parameters:
Name Type Default Description
collection string

name of the collection where to update data

id string

id of the document

db string countly

name of the database for which to write data

Returns:

bulkwrite query for document by reference, you can modify it synchronously or data may be lost

Type
object

loadConfig()

Source:

Reloads server configs

schedule()

Source:

Schedule next flush