DAO Class
Controlls the data model
Item Index
Methods
- _doQuery
- areIdsEqual static
- command
- count
- createEntity
- delete
- deleteById
- dropIndex
- ensureIndex
- entityExists
- exists
- getDb
- getIdField static
- getIDInWhere static
- getIdInWhere static
- getIDInWhere static deprecated
- getIdWhere static
- getIDWhere static deprecated
- getNotIdField static
- getNotIDField static deprecated
- getNotIdWhere static
- getNotIDWhere static deprecated
- getObjectId static
- getObjectID static deprecated
- indexInfo
- listCollections
- loadById
- loadByValue
- loadByValues
- mapSimpleIdField static
- q
- save
- saveBatch
- toArrayCursorHandler
- transfer static
- unique
- updateChangeHistory static
- updateFields
Properties
Methods
_doQuery
-
entityType -
[where={}] -
[select={}] -
[order] -
[orderBy] -
[limit] -
[offset]
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:
-
entityTypeStringThe collection to query
-
[where={}]Object optionalThe where clause
-
[select={}]Object optionalThe fields to project
-
[order]Array optionalThe ordering
-
[orderBy]Array optionalThe ordering. Parameter orderBy is deprecated, use order instead.
-
[limit]Integer optionalThe maximum number of results to return
-
[offset]Integer optionalThe number of results to skip before returning results.
Returns:
The MongoDB cursor that provides the results of the query
areIdsEqual
-
id1 -
id2
Determines if two object IDs are equal
Parameters:
-
id1ObjectID | String -
id2ObjectID | String
Returns:
TRUE if IDs are equal
command
-
The -
cb
Sends a command to the DB. http://mongodb.github.io/node-mongodb-native/api-generated/db.html#command
Parameters:
-
TheObjectcommand to execute
-
cbFunctionA callback that provides two parameters: cb(Error, [RESULT])
count
-
entityType -
where -
cb
Gets the count of objects matching criteria
Parameters:
-
entityTypeStringThe type of object to search for
-
whereObjectKey value pair object
-
cbFunctionCallback function
createEntity
-
entityName -
[options] -
cb
Creates a collection in the DB
Parameters:
-
entityNameString -
[options]Object optionalThe options for the collection. See http://mongodb.github.io/node-mongodb-native/api-generated/db.html#createcollection
-
cbFunctionA callback that takes two parameters. The first, an Error, if occurred. The second is the result of the creation command.
delete
-
where -
collection -
[options] -
cb
Removes objects from persistence that match criteria
Parameters:
-
whereObjectKey value pair object
-
collectionStringThe collection to search in
-
[options]Object optional -
cbFunctionA callback that provides two parameter. The first is an error, if occurred. The second is the number of records that were removed from persistence.
deleteById
-
oid -
collection -
[cb]
Removes an object from persistence
Parameters:
-
oidString | ObjectIDThe Id of the object to remove
-
collectionStringThe collection the object is in
-
[cb]Function optionalA 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 object iff a callback is not provided
dropIndex
-
collection -
indexName -
[options={}] -
cb
Drops the specified index from the given collection
Parameters:
-
collectionString -
indexNameString -
[options={}]Object optional -
cbFunction
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:
-
procedureObjectThe objects containing the necessary parameters and options to create the index.
-
collectionStringThe collection to build an index for
-
specObjectAn object that specifies one or more fields and sort direction for the index.
-
[options={}]Object optionalAn optional parameter that can specify the options for the index.
-
-
cbFunctionA callback that provides two parameters: cb(Error, [RESULT])
entityExists
-
entity -
cb
Determines if a collection exists in the DB
Parameters:
-
entityStringThe name of the collection
-
cbFunctionA 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:
-
collectionStringThe collection to search in
-
whereObjectKey value pair object
-
cbFunctionCallback function
getDb
-
cb
Retrieves a reference to the DB with active connection
Parameters:
-
cbFunction
getIdField
()
String
static
Retrieves the field in system objects that represents the unique identifier. The default implementation returns the mongo field '_id'.
Returns:
'_id'
getIDInWhere
-
objArray -
idProp
Creates a where clause that equates to select where [idProp] is not in the specified array of values.
Parameters:
-
objArrayArrayThe array of acceptable values
-
idPropStringThe property that holds a referenced ID value
Returns:
Where clause
getIdInWhere
-
objArray -
[idProp]
Creates a where clause that equates to select where [idProp] is in the specified array of values.
Parameters:
-
objArrayArrayThe array of acceptable values
-
[idProp]String optionalThe property that holds a referenced ID value
Returns:
Where clause
getIDInWhere
-
objArray -
idProp
Creates a where clause that equates to select where [idProp] is in the specified array of values.
Parameters:
-
objArrayArrayThe array of acceptable values
-
idPropStringThe property that holds a referenced ID value
Returns:
Where clause
getIdWhere
-
oid
Creates a basic where clause based on the specified Id
Parameters:
-
oidStringObject Id String
Returns:
Where clause
getIDWhere
-
oid
Creates a basic where clause based on the specified Id
Parameters:
-
oidStringObject Id String
Returns:
Where clause
getNotIdField
()
Object
static
Creates a where clause that indicates to select where the '_id' field does not equal the specified value.
Returns:
Where clause
getNotIDField
()
Object
deprecated
static
Creates a where clause that indicates to select where the '_id' field does not equal the specified value.
Returns:
Where clause
getNotIdWhere
-
oid
Creates a basic where clause based on not equalling the specified Id
Parameters:
-
oidStringObject Id String
Returns:
Where clause
getNotIDWhere
-
oid
Creates a basic where clause based on not equalling the specified Id
Parameters:
-
oidStringObject Id String
Returns:
Where clause
getObjectId
-
oid
Creates an MongoDB ObjectID object
Parameters:
-
oidStringObject Id String
Returns:
ObjectID object
getObjectID
-
oid
Creates an MongoDB ObjectID object
Parameters:
-
oidStringObject Id String
Returns:
ObjectID object
indexInfo
-
collection -
[options={}] -
cb
Retrieves indexes for the specified collection
Parameters:
-
collectionString -
[options={}]Object optional -
cbFunction
listCollections
-
[filter] -
cb
Gets all collection names
Parameters:
-
[filter]Object optionalThe filter to specify what collection(s) to search for
-
cbFunctionA 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:
-
idStringThe unique id of the object
-
collectionStringThe collection the object is in
-
KeyObjectvalue pair object to exclude the retrival of data
-
cbFunctionCallback function
loadByValue
-
key -
val -
collection -
[opts] -
cb
Retrieves objects matching a key value pair
Parameters:
-
keyStringThe key to search for
-
valThe value to search for
-
collectionStringThe collection to search in
-
[opts]Object optionalKey value pair object to exclude the retrieval of data
-
cbFunctionCallback function
loadByValues
-
where -
collection -
[opts] -
cb
Retrieves object matching several key value pairs
Parameters:
-
whereObjectKey value pair object
-
collectionStringThe collection to search in
-
[opts]Object optionalKey value pair object to exclude the retrieval of data
-
cbFunctionCallback function
mapSimpleIdField
-
doc
Used to help transition over to eliminating the MongoDB _id field.
Parameters:
-
docObject
Returns:
q
-
collection -
[options] -
cb
Queries the database. Added in the 0.2.5 release
Parameters:
-
collectionStringThe type of object to search for
-
[options]Object optionalThe options for the query
-
[where={}]Object optionalThe conditions under which results are returned
-
[select]Object optionalSelection type object
-
[order]Array optionalOrder by array (MongoDB syntax)
-
[limit]Integer optionalNumber of documents to retrieve
-
[offset]Integer optionalStart index of retrieval
-
[handler]Function optionalA 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.
-
-
cbFunctionA 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:
-
dbObjObjectThe system object to persist
-
[options]Object optional -
cbFunctionA callback that takes two parameters. The first, an error, if occurred. The second is the object that was persisted
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:
-
objArrayArrayThe array of objects to persist
-
collectionStringThe collection to persist the objects to
-
[options]Object optional -
cbFunctionA callback that takes two arguments. The first is an error, if occurred. The second is the second parameter of the callback described here: http://mongodb.github.io/node-mongodb-native/api-generated/unordered.html#execute
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:
-
cursorCursor -
cbFunction
transfer
-
obj -
to
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:
-
objObjectThe object to convert
-
toStringThe type to convert it to
unique
-
collection -
where -
[exclusionId] -
cb
Determines if there is only a single document that matches the specified query
Parameters:
-
collectionStringThe collection to search in
-
whereObjectKey value pair object
-
[exclusionId]String optionalObject Id to exclude from the search
-
cbFunctionCallback function
updateChangeHistory
-
dbObject
Updates a DB object with a created time stamp and last modified time stamp.
Parameters:
-
dbObjectObjectObject to update
updateFields
-
collection -
query -
updates -
[options] -
cb
Updates a specific set of fields. This is handy for performing upserts.
Parameters:
-
collectionStringThe collection to update object(s) in
-
queryObjectThe where clause to execute to find the existing object
-
updatesObjectThe updates to perform
-
[options]Object optionalAny options to go along with the update
-
[upsert=false]Boolean optionalInserts the object is not found
-
[multi=false]Boolean optionalUpdates multiple records if the query finds more than 1
-
-
cbFunction
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
