API Docs for: 0.8.0
Show:

DAO Class

Defined in: include/dao/dao.js:25
Module: Database

Controlls the data model

Methods

_doQuery

(
  • entityType
  • [where={}]
  • [select={}]
  • [order]
  • [orderBy]
  • [limit]
  • [offset]
)
Cursor protected

The actual implementation for querying. The function does not do the same type checking as the wrapper function "query". This funciton is responsible for doing the heavy lifting and returning the result back to the calling intity.

Parameters:

  • entityType String

    The collection to query

  • [where={}] Object optional

    The where clause

  • [select={}] Object optional

    The fields to project

  • [order] Array optional

    The ordering

  • [orderBy] Array optional

    The ordering. Parameter orderBy is deprecated, use order instead.

  • [limit] Integer optional

    The maximum number of results to return

  • [offset] Integer optional

    The number of results to skip before returning results.

Returns:

Cursor:

The MongoDB cursor that provides the results of the query

areIdsEqual

(
  • id1
  • id2
)
Boolean static

Determines if two object IDs are equal

Parameters:

  • id1 ObjectID | String
  • id2 ObjectID | String

Returns:

Boolean:

TRUE if IDs are equal

command

(
  • The
  • cb
)

Parameters:

  • The Object

    command to execute

  • cb Function

    A callback that provides two parameters: cb(Error, [RESULT])

count

(
  • entityType
  • where
  • cb
)

Gets the count of objects matching criteria

Parameters:

  • entityType String

    The type of object to search for

  • where Object

    Key value pair object

  • cb Function

    Callback function

createEntity

(
  • entityName
  • [options]
  • cb
)

Creates a collection in the DB

Parameters:

delete

(
  • where
  • collection
  • [options]
  • cb
)

Removes objects from persistence that match criteria

Parameters:

deleteById

(
  • oid
  • collection
  • [cb]
)
Promise

Removes an object from persistence

Parameters:

  • oid String | ObjectID

    The Id of the object to remove

  • collection String

    The collection the object is in

  • [cb] Function optional

    A callback that takes two parameters. The first is an error, if occurred. The second is the number of records deleted by the execution of the command.

Returns:

Promise:

Promise object iff a callback is not provided

dropIndex

(
  • collection
  • indexName
  • [options={}]
  • cb
)

Drops the specified index from the given collection

Parameters:

  • collection String
  • indexName String
  • [options={}] Object optional
  • cb Function

ensureIndex

(
  • procedure
  • cb
)

Attempts to create an index. If the collection already exists then the operation is skipped. http://mongodb.github.io/node-mongodb-native/api-generated/collection.html#ensureindex

Parameters:

  • procedure Object

    The objects containing the necessary parameters and options to create the index.

    • collection String

      The collection to build an index for

    • spec Object

      An object that specifies one or more fields and sort direction for the index.

    • [options={}] Object optional

      An optional parameter that can specify the options for the index.

  • cb Function

    A callback that provides two parameters: cb(Error, [RESULT])

entityExists

(
  • entity
  • cb
)

Determines if a collection exists in the DB

Parameters:

  • entity String

    The name of the collection

  • cb Function

    A callback that takes two parameters. The first, an error, if occurred. The second is a boolean where TRUE means the entity exists, FALSE if not.

exists

(
  • collection
  • where
  • cb
)

Determines if an object extists matching criteria

Parameters:

  • collection String

    The collection to search in

  • where Object

    Key value pair object

  • cb Function

    Callback function

getDb

(
  • cb
)

Retrieves a reference to the DB with active connection

Parameters:

  • cb Function

getIdField

() String static

Retrieves the field in system objects that represents the unique identifier. The default implementation returns the mongo field '_id'.

Returns:

String:

'_id'

getIDInWhere

(
  • objArray
  • idProp
)
Object static

Creates a where clause that equates to select where [idProp] is not in the specified array of values.

Parameters:

  • objArray Array

    The array of acceptable values

  • idProp String

    The property that holds a referenced ID value

Returns:

Object:

Where clause

getIdInWhere

(
  • objArray
  • [idProp]
)
Object static

Creates a where clause that equates to select where [idProp] is in the specified array of values.

Parameters:

  • objArray Array

    The array of acceptable values

  • [idProp] String optional

    The property that holds a referenced ID value

Returns:

Object:

Where clause

getIDInWhere

(
  • objArray
  • idProp
)
Object deprecated static

Creates a where clause that equates to select where [idProp] is in the specified array of values.

Parameters:

  • objArray Array

    The array of acceptable values

  • idProp String

    The property that holds a referenced ID value

Returns:

Object:

Where clause

getIdWhere

(
  • oid
)
Object static

Creates a basic where clause based on the specified Id

Parameters:

  • oid String

    Object Id String

Returns:

Object:

Where clause

getIDWhere

(
  • oid
)
Object deprecated static

Defined in include/dao/dao.js:730

Deprecated: since 0.4.0

Creates a basic where clause based on the specified Id

Parameters:

  • oid String

    Object Id String

Returns:

Object:

Where clause

getNotIdField

() Object static

Creates a where clause that indicates to select where the '_id' field does not equal the specified value.

Returns:

Object:

Where clause

getNotIDField

() Object deprecated static

Defined in include/dao/dao.js:855

Deprecated: since 0.4.0

Creates a where clause that indicates to select where the '_id' field does not equal the specified value.

Returns:

Object:

Where clause

getNotIdWhere

(
  • oid
)
Object static

Creates a basic where clause based on not equalling the specified Id

Parameters:

  • oid String

    Object Id String

Returns:

Object:

Where clause

getNotIDWhere

(
  • oid
)
Object deprecated static

Creates a basic where clause based on not equalling the specified Id

Parameters:

  • oid String

    Object Id String

Returns:

Object:

Where clause

getObjectId

(
  • oid
)
Object static

Creates an MongoDB ObjectID object

Parameters:

  • oid String

    Object Id String

Returns:

Object:

ObjectID object

getObjectID

(
  • oid
)
Object deprecated static

Defined in include/dao/dao.js:879

Deprecated: since 0.4.0

Creates an MongoDB ObjectID object

Parameters:

  • oid String

    Object Id String

Returns:

Object:

ObjectID object

indexInfo

(
  • collection
  • [options={}]
  • cb
)

Retrieves indexes for the specified collection

Parameters:

  • collection String
  • [options={}] Object optional
  • cb Function

listCollections

(
  • [filter]
  • cb
)

Gets all collection names

Parameters:

  • [filter] Object optional

    The filter to specify what collection(s) to search for

  • cb Function

    A callback that takes two parameters. The first, an Error, if occurred. The second is the result listCollections command.

loadById

(
  • id
  • collection
  • Key
  • cb
)

Retrieves an object by ID

Parameters:

  • id String

    The unique id of the object

  • collection String

    The collection the object is in

  • Key Object

    value pair object to exclude the retrival of data

  • cb Function

    Callback function

loadByValue

(
  • key
  • val
  • collection
  • [opts]
  • cb
)

Retrieves objects matching a key value pair

Parameters:

  • key String

    The key to search for

  • val

    The value to search for

  • collection String

    The collection to search in

  • [opts] Object optional

    Key value pair object to exclude the retrieval of data

  • cb Function

    Callback function

loadByValues

(
  • where
  • collection
  • [opts]
  • cb
)

Retrieves object matching several key value pairs

Parameters:

  • where Object

    Key value pair object

  • collection String

    The collection to search in

  • [opts] Object optional

    Key value pair object to exclude the retrieval of data

  • cb Function

    Callback function

mapSimpleIdField

(
  • doc
)
Object static

Used to help transition over to eliminating the MongoDB _id field.

Parameters:

  • doc Object

Returns:

Object:

q

(
  • collection
  • [options]
  • cb
)

Queries the database. Added in the 0.2.5 release

Parameters:

  • collection String

    The type of object to search for

  • [options] Object optional

    The options for the query

    • [where={}] Object optional

      The conditions under which results are returned

    • [select] Object optional

      Selection type object

    • [order] Array optional

      Order by array (MongoDB syntax)

    • [limit] Integer optional

      Number of documents to retrieve

    • [offset] Integer optional

      Start index of retrieval

    • [handler] Function optional

      A function that takes two paramters. The first, the Cursor object that contains the results of the query. The second is a callback that takes two parameters. An error if occurred and by default, the documents returned by the query. Custom handlers may provide whatever value it wishes including the cursor if it wishes to handle the results itself.

  • cb Function

    A callback function that takes two parameters. The first, an error, if occurred and the second is the result provided by the handler. By default it provides an array of objects that represent the items returned by the query.

save

(
  • dbObj
  • [options]
  • cb
)

Inserts or replaces an existing document with the specified DB Object. An insert is distinguished from an update based the presence of the _id field.

Parameters:

saveBatch

(
  • objArray
  • collection
  • [options]
  • cb
)

Provides a mechanism to save an array of objects all from the same collection. The function handles updates and inserts. The difference is determined by the truth value of the ID field of each object.

Parameters:

toArrayCursorHandler

(
  • cursor
  • cb
)

A cursor handler that iterates over each result from the query that created the cursor and places the result into an array. The array of documents is provided as the second argument in the callback.

Parameters:

  • cursor Cursor
  • cb Function

transfer

(
  • obj
  • to
)
static

Transfers a system object from one type to another. The system specific properties are cleared so that when the object is persisted it will receive its own properties.

Parameters:

  • obj Object

    The object to convert

  • to String

    The type to convert it to

unique

(
  • collection
  • where
  • [exclusionId]
  • cb
)

Determines if there is only a single document that matches the specified query

Parameters:

  • collection String

    The collection to search in

  • where Object

    Key value pair object

  • [exclusionId] String optional

    Object Id to exclude from the search

  • cb Function

    Callback function

updateChangeHistory

(
  • dbObject
)
static

Updates a DB object with a created time stamp and last modified time stamp.

Parameters:

  • dbObject Object

    Object to update

updateFields

(
  • collection
  • query
  • updates
  • [options]
  • cb
)

Updates a specific set of fields. This is handy for performing upserts.

Parameters:

  • collection String

    The collection to update object(s) in

  • query Object

    The where clause to execute to find the existing object

  • updates Object

    The updates to perform

  • [options] Object optional

    Any options to go along with the update

    • [upsert=false] Boolean optional

      Inserts the object is not found

    • [multi=false] Boolean optional

      Updates multiple records if the query finds more than 1

  • cb Function

Properties

ANYWHERE

Object

Static variable to indicate that documents should be retrieve from anywhere

ASC

Number

Static varible to sort ascending

dbName

String

The name of the DB that this instance is intended to interact with. By default, it goes to the name of the DB provided by system configuration property db.name.

DESC

Number

Static variable to sort descending

NATURAL_ORDER

Array

Static variable to indicate that documents should be returned in their natural order

PROJECT_ALL

Object

Static variable to indicate that all indices of a document should be retrieved