CollectionApi

CollectionApi

new CollectionApi(database, name, req, res, internal)

An api wrapper for a single collection using internally a Store.
Parameters:
Name Type Description
database Database The database instance
name string The collection name.
req HttpRequest The http request object
res HttpResponse The http response object
internal boolean Whether the collection Api is in internal mode or not
Properties:
Name Type Description
database Database The database instance
name string The collection name.
req HttpRequest The http request object
res HttpResponse The http response object
internal boolean Whether the collection Api is in internal mode or not

Methods

count(query, cb)

Counts data from the collection.
Parameters:
Name Type Description
query object The query
cb CollectionApi~countCallback The callback function
Example
api.collection.count({
  firstName: 'John',
  lastName: 'Smith'
}, function (err, res) {
  if(err)
     throw err
})

del(query, cb)

Delete data from the collection.
Parameters:
Name Type Description
query object The query
cb Store~delCallback The callback function
Example
api.collection.del({
  firstName: 'John',
  lastName: 'Smith'
}, function (err, res) {
  if(err)
     throw err
})

get(query, cb)

Get data from the collection.
Parameters:
Name Type Description
query object The query
cb CollectionApi~getCallback The callback function
Example
api.collection.get({
  firstName: 'John'
  $single: true,
  $cached: true,
  $fields: {
    firstName: 1,
    lastName: 1
  },
  $limit: 100,
  $sort: {
    firstName: 1
  }
}, function (err, res) {
  if(err)
     throw err
})

post(data, cb)

Post new data to the collection.
Parameters:
Name Type Description
data object The data to post
cb CollectionApi~postCallback The callback function
Example
api.collection.post({
  firstName: 'John',
  lastName: 'Smith'
}, function (err, res) {
  if(err)
     throw err
})

put(query, data, cb)

Update data in the collection.
Parameters:
Name Type Description
query object The query
data object The data
cb CollectionApi~putCallback The callback function
Example
api.collection.put({
  firstName: 'John',
  lastName: 'Smith'
}, {
  firstName: 'John2',
  lastName: 'Smith2'
}, function (err, res) {
  if(err)
     throw err
})

Type Definitions

countCallback(err, res)

Parameters:
Name Type Description
err Exception The exception object
res object The count result

delCallback(err, res)

Parameters:
Name Type Description
err Exception The exception object
res object The delete results

dropCallback(err, res)

Parameters:
Name Type Description
err Exception The exception object
res object The drop result

getCallback(err, res)

Parameters:
Name Type Description
err Exception The exception object
res object The results

postCallback(err, res)

Parameters:
Name Type Description
err Exception The exception object
res object The posted results

putCallback(err, res)

Parameters:
Name Type Description
err Exception The exception object
res object The update results