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:
-
entityType
StringThe 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:
-
id1
ObjectID | String -
id2
ObjectID | 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:
-
The
Objectcommand to execute
-
cb
FunctionA callback that provides two parameters: cb(Error, [RESULT])
count
-
entityType
-
where
-
cb
Gets the count of objects matching criteria
Parameters:
-
entityType
StringThe type of object to search for
-
where
ObjectKey value pair object
-
cb
FunctionCallback function
createEntity
-
entityName
-
[options]
-
cb
Creates a collection in the DB
Parameters:
-
entityName
String -
[options]
Object optionalThe options for the collection. See http://mongodb.github.io/node-mongodb-native/api-generated/db.html#createcollection
-
cb
FunctionA 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:
-
where
ObjectKey value pair object
-
collection
StringThe collection to search in
-
[options]
Object optional -
cb
FunctionA 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:
-
oid
String | ObjectIDThe Id of the object to remove
-
collection
StringThe 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:
-
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
ObjectThe objects containing the necessary parameters and options to create the index.
-
collection
StringThe collection to build an index for
-
spec
ObjectAn 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.
-
-
cb
FunctionA callback that provides two parameters: cb(Error, [RESULT])
entityExists
-
entity
-
cb
Determines if a collection exists in the DB
Parameters:
-
entity
StringThe name of the collection
-
cb
FunctionA 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
StringThe collection to search in
-
where
ObjectKey value pair object
-
cb
FunctionCallback 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:
'_id'
getIDInWhere
-
objArray
-
idProp
Creates a where clause that equates to select where [idProp] is not in the specified array of values.
Parameters:
-
objArray
ArrayThe array of acceptable values
-
idProp
StringThe 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:
-
objArray
ArrayThe 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:
-
objArray
ArrayThe array of acceptable values
-
idProp
StringThe property that holds a referenced ID value
Returns:
Where clause
getIdWhere
-
oid
Creates a basic where clause based on the specified Id
Parameters:
-
oid
StringObject Id String
Returns:
Where clause
getIDWhere
-
oid
Creates a basic where clause based on the specified Id
Parameters:
-
oid
StringObject 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:
-
oid
StringObject Id String
Returns:
Where clause
getNotIDWhere
-
oid
Creates a basic where clause based on not equalling the specified Id
Parameters:
-
oid
StringObject Id String
Returns:
Where clause
getObjectId
-
oid
Creates an MongoDB ObjectID object
Parameters:
-
oid
StringObject Id String
Returns:
ObjectID object
getObjectID
-
oid
Creates an MongoDB ObjectID object
Parameters:
-
oid
StringObject Id String
Returns:
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 optionalThe filter to specify what collection(s) to search for
-
cb
FunctionA 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
StringThe unique id of the object
-
collection
StringThe collection the object is in
-
Key
Objectvalue pair object to exclude the retrival of data
-
cb
FunctionCallback function
loadByValue
-
key
-
val
-
collection
-
[opts]
-
cb
Retrieves objects matching a key value pair
Parameters:
-
key
StringThe key to search for
-
val
The value to search for
-
collection
StringThe collection to search in
-
[opts]
Object optionalKey value pair object to exclude the retrieval of data
-
cb
FunctionCallback function
loadByValues
-
where
-
collection
-
[opts]
-
cb
Retrieves object matching several key value pairs
Parameters:
-
where
ObjectKey value pair object
-
collection
StringThe collection to search in
-
[opts]
Object optionalKey value pair object to exclude the retrieval of data
-
cb
FunctionCallback function
mapSimpleIdField
-
doc
Used to help transition over to eliminating the MongoDB _id field.
Parameters:
-
doc
Object
Returns:
q
-
collection
-
[options]
-
cb
Queries the database. Added in the 0.2.5 release
Parameters:
-
collection
StringThe 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.
-
-
cb
FunctionA 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:
-
dbObj
ObjectThe system object to persist
-
[options]
Object optional -
cb
FunctionA 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:
-
objArray
ArrayThe array of objects to persist
-
collection
StringThe collection to persist the objects to
-
[options]
Object optional -
cb
FunctionA 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:
-
cursor
Cursor -
cb
Function
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:
-
obj
ObjectThe object to convert
-
to
StringThe 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
StringThe collection to search in
-
where
ObjectKey value pair object
-
[exclusionId]
String optionalObject Id to exclude from the search
-
cb
FunctionCallback function
updateChangeHistory
-
dbObject
Updates a DB object with a created time stamp and last modified time stamp.
Parameters:
-
dbObject
ObjectObject to update
updateFields
-
collection
-
query
-
updates
-
[options]
-
cb
Updates a specific set of fields. This is handy for performing upserts.
Parameters:
-
collection
StringThe collection to update object(s) in
-
query
ObjectThe where clause to execute to find the existing object
-
updates
ObjectThe 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
-
-
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