MongoDatabase
Summary
Defines a MongoDB Database.
Constructor
MongoDatabase
Syntax
MongoDatabase
-
configuration
Summary
Parameters:
-
configurationObjectA database configuration object
-
hostStringMongoDB server host
-
portNumberMongoDB server port
-
databaseStringThe name of the database
-
usernameStringThe name of the database user
-
passwordStringThe password of the database user
-
[replicaSet]String optionalThe name of the ReplicaSet
-
[seedlist]String optionalThe comma separated list of secondary servers
-
Item Index
Methods
- add
- buildFields static
- buildFilter static
- buildSort static
- close
- connect
- createIndexes
- get
- getIndexes
- getOne
- getStore
- remove
- removeCollection
- removeField
- renameCollection
- update
Properties
Methods
add
Syntax
add
-
collection -
documents -
callback
Summary
Inserts several documents into a collection.
buildFields
Syntax
Summary
Builds MongoDb fields projection.
Parameters:
Returns:
The MongoDB projection description object
buildFilter
Syntax
Summary
Builds MongoDb filter from a ResourceFilter.
Parameters:
-
resourceFilterResourceFilterThe common resource filter
Returns:
The MongoDB like filter description object
buildSort
Syntax
Summary
Builds MongoDB sort object.
Concretely it just replaces "asc" by 1 and "desc" by -1.
Parameters:
-
[sort]Object optionalThe list of fields to sort by with the field name as key and the sort order as value (e.g. {field1: 'asc', field2: 'desc'})
Returns:
The MongoDB sort description object
close
Syntax
close
-
callback
Summary
Closes connection to the database.
Parameters:
-
callbackFunctionThe function to call when connection is closed
- Error The error if an error occurred, null otherwise
connect
Syntax
connect
-
callback
Summary
Establishes connection to the database.
Parameters:
-
callbackFunctionThe function to call when connection to the database is established
- Error The error if an error occurred, null otherwise
createIndexes
Syntax
createIndexes
-
collection -
indexes -
callback
Summary
Creates indexes for a collection.
get
Syntax
get
-
collection -
[filter] -
[fields] -
[limit] -
[page] -
[sort] -
callback
Summary
Fetches documents from the collection.
Parameters:
-
collectionStringThe collection to work on
-
[filter]ResourceFilter optionalRules to filter documents
-
[fields]Object optionalExpected resource fields to be included or excluded from the response, by default all fields are returned. Only "exclude" or "include" can be specified, not both
-
[limit]Number optionalA limit number of documents to retrieve (10 by default)
-
[page]Number optionalThe page number started at 0 for the first page
-
[sort]Object optionalThe list of fields to sort by with the field name as key and the sort order as value (e.g. {field1: 'asc', field2: 'desc'})
-
callbackFunctionThe function to call when it's done
- Error The error if an error occurred, null otherwise
- Array The list of retrieved documents
- Object Pagination information
- Number limit The specified limit
- Number page The actual page
- Number pages The total number of pages
- Number size The total number of documents
getIndexes
Syntax
getIndexes
-
collection -
callback
Summary
Gets the list of indexes for a collection.
getOne
Syntax
getOne
-
collection -
[filter] -
[fields] -
callback
Summary
Fetches a single document from the storage.
Parameters:
-
collectionStringThe collection to work on
-
[filter]ResourceFilter optionalRules to filter documents
-
[fields]Object optionalExpected document fields to be included or excluded from the response, by default all fields are returned. Only "exclude" or "include" can be specified, not both
-
callbackFunctionThe function to call when it's done
- Error The error if an error occurred, null otherwise
- Object The document
getStore
Syntax
getStore
-
collection
Summary
Gets an express-session store for this database.
Parameters:
-
collectionStringThe collection to work on
Returns:
An express-session store
remove
Syntax
remove
-
collection -
[filter] -
callback
Summary
Removes several documents from a collection.
Parameters:
-
collectionStringThe collection to work on
-
[filter]ResourceFilter optionalRules to filter documents to remove
-
callbackFunctionThe function to call when it's done
- Error The error if an error occurred, null otherwise
- Number The number of deleted documents
removeCollection
Syntax
removeCollection
-
collection -
callback
Summary
Remove a collection from the database
removeField
Syntax
removeField
-
collection -
property -
[filter] -
callback
Summary
Removes a property from documents of a collection.
Parameters:
-
collectionStringThe collection to work on
-
propertyStringThe name of the property to remove
-
[filter]ResourceFilter optionalRules to filter documents to update
-
callbackFunctionThe function to call when it's done
- Error The error if an error occurred, null otherwise
- Number The number of updated documents
renameCollection
Syntax
renameCollection
-
collection -
target -
callback
Summary
Renames a collection.
update
Syntax
update
-
collection -
[filter] -
data -
callback
Summary
Updates documents from collection.
Parameters:
-
collectionStringThe collection to work on
-
[filter]ResourceFilter optionalRules to filter documents to update
-
dataObjectThe modifications to perform
-
callbackFunctionThe function to call when it's done
- Error The error if an error occurred, null otherwise
- Number The number of updated documents
Properties
database
Syntax
database
Db
final
Summary
The connected database.