Mongoable

Mongoable

Base class for MongoDB-backed instances

Constructor

new Mongoable()

Source:
See:
  • push/api/data/* for examples

Members

_id

Description:
  • Getter for id as is

Source:

Getter for id as is

_id

Description:
  • Setter for _id

Source:

Setter for _id

id

Description:
  • Getter for id as a string

Source:

Getter for id as a string

(static) collection

Description:
  • Must be overridden in subclasses to return collection name

Source:

Must be overridden in subclasses to return collection name

Methods

(async) refresh() → {This|boolean}

Description:
  • Refresh current instance with data from the database

Source:
Returns:

this instance of this class if the record is found in database, false otherwise

Type
This | boolean

(async) save()

Description:
  • Pass current data to mongo's save

Source:

(async) update(update, op)

Description:
  • Run an update operation modifying this's _data

Source:
Parameters:
Name Type Description
update object | string

query for an update

op function

op to run to modify state of this in case of success

(async) updateAtomically(filter, update) → {boolean}

Description:
  • Run an atomic update operation against filter with modifications in update, updating instance data with latest version in case of success

Source:
Parameters:
Name Type Description
filter object | string

filter for an update

update object | string

modify for a findAndModify

Returns:

true in case of success, false otherwise

Type
boolean

(static) batchInsert(batch) → {object}

Description:
  • Simple batch insert object:

    let batch = Model.batchInsert(3); await batch.pushAsync({a: 1}); await batch.pushAsync({a: 2}); await batch.pushAsync({a: 3}); // <- insertMany here await batch.pushAsync({a: 4}); ... await batch.flush(); // flush the rest

    --- or ---

    for (let n of [1, 2, 3]) { if (batch.pushSync({a: 1})) { await batch.flush(); } }

Source:
Parameters:
Name Type Default Description
batch number 10000

batch size

Returns:

with 2 async methods: push(record) and flush()

Type
object

(async, static) count(query) → {Number}

Description:
  • Count records in collection

Source:
Parameters:
Name Type Description
query object

query for count

Returns:

count of records in collection satisfying the query

Type
Number

(async, static) deleteOne(query) → {Number}

Description:
  • Delete record from collection

Source:
Parameters:
Name Type Description
query object

query for count

Returns:

count of records in collection satisfying the query

Type
Number

(async, static) findMany(query) → {Array.<This>}

Description:
  • Find multiple records in db and map them to instances of this class

Source:
Parameters:
Name Type Description
query object | string

query for find

Returns:

array of instances of this class if the records are found in the database, empty array otherwise

Type
Array.<This>

(async, static) findOne(query) → {This|null}

Description:
  • Find a record in db and map it to instance of this class

Source:
Parameters:
Name Type Description
query object | string

query for findOne

Returns:

instance of this class if the record is found in database, null otherwise

Type
This | null

(async, static) findOneAndUpdate(filter, update) → {boolean}

Description:
  • Run an atomic update operation against filter with modifications in update, updating instance data with latest version in case of success

Source:
Parameters:
Name Type Description
filter object | string

filter for an update

update object | string

modify for a findAndModify

Returns:

true in case of success, false otherwise

Type
boolean