MongoDatabase
Summary
Defines a MongoDB Database.
Constructor
MongoDatabase
Syntax
MongoDatabase
-
configuration
Summary
Parameters:
-
configuration
ObjectA database configuration object
-
host
StringMongoDB server host
-
port
NumberMongoDB server port
-
database
StringThe name of the database
-
username
StringThe name of the database user
-
password
StringThe password of the database user
-
[replicaSet]
String optionalThe name of the ReplicaSet
-
[seedlist]
String optionalThe comma separated list of secondary servers
-
Item Index
Methods
Properties
Methods
add
Syntax
add
-
collection
-
documents
-
callback
Summary
Inserts several documents into a collection.
Parameters:
buildFields
Syntax
Summary
Builds MongoDb fields projection.
Parameters:
Returns:
The MongoDB projection description object
buildFilter
Syntax
Summary
Builds MongoDb filter from a ResourceFilter.
Parameters:
-
resourceFilter
ResourceFilterThe common resource filter
Returns:
The MongoDB like filter description object
buildSort
Syntax
Summary
Builds MongoDB sort object.
Concretely it just replaces "score" by "{ $meta: 'textScore' }", "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', field3: 'score'})
Returns:
The MongoDB sort description object
close
Syntax
close
-
callback
Summary
Closes connection to the database.
Parameters:
-
callback
FunctionThe 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:
-
callback
FunctionThe 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.
dropIndex
Syntax
dropIndex
-
collection
-
indexName
-
callback
Summary
Drops an index from a collection.
get
Syntax
get
-
collection
-
[filter]
-
[fields]
-
[limit]
-
[page]
-
sort
-
callback
Summary
Fetches documents from the collection.
Parameters:
-
collection
StringThe 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
ObjectThe list of fields to sort by with the field name as key and the sort order as value (e.g. {field1: 'asc', field2: 'desc', field3: 'score'})
-
callback
FunctionThe 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:
-
collection
StringThe 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
-
callback
FunctionThe 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:
-
collection
StringThe collection to work on
Returns:
An express-session store
remove
Syntax
remove
-
collection
-
[filter]
-
callback
Summary
Removes several documents from a collection.
Parameters:
-
collection
StringThe collection to work on
-
[filter]
ResourceFilter optionalRules to filter documents to remove
-
callback
FunctionThe 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
Removes a collection from the database.
removeField
Syntax
removeField
-
collection
-
property
-
[filter]
-
callback
Summary
Removes a property from documents of a collection.
Parameters:
-
collection
StringThe collection to work on
-
property
StringThe name of the property to remove
-
[filter]
ResourceFilter optionalRules to filter documents to update
-
callback
FunctionThe 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.
updateOne
Syntax
updateOne
-
collection
-
[filter]
-
data
-
callback
Summary
Updates a document from collection.
Parameters:
-
collection
StringThe collection to work on
-
[filter]
ResourceFilter optionalRules to filter the document to update
-
data
ObjectThe modifications to perform
-
callback
FunctionThe function to call when it's done
- Error The error if an error occurred, null otherwise
- Number 1 if everything went fine
Properties
client
Syntax
client
MongoClient
final
Summary
The MongoDB client instance.
database
Syntax
database
Db
final
Summary
The connected database.