Constructor
new WriteBatcher(db)
- Description:
Create batcher instance
- Source:
Example
let batcher = new WriteBatcher(common.db);
batcher.add("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, optionsopt)
- Description:
Provide operation for document id and batcher will try to merge multiple operations
- Source:
Parameters:
| Name | Type | Attributes | 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 |
|
options |
object |
<optional> |
options for operation ((upsert: false) - if you don't want to upsert document) |
addDb(name, connection)
- Description:
Add another database to batch
- Source:
Parameters:
| Name | Type | Description |
|---|---|---|
name |
string | name of the database |
connection |
Db | MongoDB connection to that database |
(async) flush(db, collection)
- Description:
Writes data to database for specific collection
- Source:
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}
- Description:
Run all pending database queries
- Source:
Returns:
promise
- Type
- Promise
get(collection, id, db) → {object}
- Description:
Get operation on document by id
- Source:
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()
- Description:
Reloads server configs
- Source:
schedule()
- Description:
Schedule next flush
- Source: