Home Identifier Source Repository
import MongoStorage from 'piggy-module/src/Storage/Mongo.js'
public class | source

MongoStorage

Extends:

src/Storage/Abstract~AbstractStorage → MongoStorage

Manage data from a mongodb collection.

Constructor Summary

Public Constructor
public

constructor(collection: Object)

Method Summary

Public Methods
public

delete(criteria: Object): Promise<integer, Error>

Delete collection Object from criteria

public

get(criteria: Object, options: Object): Promise<Object[], Error>

Get a list of data Object from criteria and options

public

getByPage(criteria: Object, page: integer, limit: integer, orderby: string, order: string): Promise<Object[], Error>

Get a paginated list of data Object

public

insert(dataArray: Object[]): Promise<Object[], Error>

Insert many data Object in database

public

update(criteria: Object, newValues: Object, options: Object): Promise<integer, Error>

Update collection from criteria

Public Constructors

public constructor(collection: Object) source

Params:

NameTypeAttributeDescription
collection Object

A mongodb collection

Public Methods

public delete(criteria: Object): Promise<integer, Error> source

Delete collection Object from criteria

Params:

NameTypeAttributeDescription
criteria Object

MongoDb criteria Object

Return:

Promise<integer, Error>

number of deleted items

public get(criteria: Object, options: Object): Promise<Object[], Error> source

Get a list of data Object from criteria and options

Params:

NameTypeAttributeDescription
criteria Object

mongodb criteria style

options Object

mongodb options style

Return:

Promise<Object[], Error>

public getByPage(criteria: Object, page: integer, limit: integer, orderby: string, order: string): Promise<Object[], Error> source

Get a paginated list of data Object

Params:

NameTypeAttributeDescription
criteria Object

mongodb criteria style

page integer

the page to retrieve

limit integer

number of item per page

orderby string

a mongodb collection property to order the list result

order string

'asc' or 'desc'

Return:

Promise<Object[], Error>

public insert(dataArray: Object[]): Promise<Object[], Error> source

Insert many data Object in database

Params:

NameTypeAttributeDescription
dataArray Object[]

a list of data Object

Return:

Promise<Object[], Error>

inserted data Object list

public update(criteria: Object, newValues: Object, options: Object): Promise<integer, Error> source

Update collection from criteria

Params:

NameTypeAttributeDescription
criteria Object

MongoDb criteria Object

newValues Object

key-value Object with new data

options Object

MongoDb options

options.upsert boolean

insert if not exists

options.multi boolean

update multi Object enabled

Return:

Promise<integer, Error>

number of updated items