MongoDatabase
Summary
Defines a MongoDB Database.
MongoDatabase must not be used directly. Use Database to get an instance of MongoDatabase.
Constructor
MongoDatabase
Syntax
MongoDatabase
-
Object
Summary
Parameters:
-
ObjectObjectdatabaseConf A database configuration object
Example:
var api = require('@openveo/api');
// Example of a MongoDB database configuration object
var databaseConf = {
"type" : "mongodb", // Database type
"host" : "localhost", // MongoDB server host
"port" : 27017, // MongoDB port
"database" : "DATABASE_NAME", // Replace DATABASE_NAME by the name of the OpenVeo database
"username" : "DATABASE_USER_NAME", // Replace DATABASE_USER_NAME by the name of the database user
"password" : "DATABASE_USER_PWD", // Replace DATABASE_USER_PWD by the password of the database user
"replicaSet" : "REPLICA_SET_NAME", // Replace REPLICA_SET_NAME by the name of the ReplicaSet
"seedlist": "IP_1:PORT_1,IP_2:PORT_2" // The comma separated list of secondary servers
};
// Get a MongoDB database instance
var db = api.Database.getDatabase(databaseConf);
Item Index
Methods
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 -
[criteria] -
[projection] -
[limit] -
callback
Summary
Gets a list of documents.
Parameters:
-
collectionStringThe collection to work on
-
[criteria]Object optionalMongoDB criterias
-
[projection]Object optionalMongoDB projection
-
[limit]Number optionalA limit number of items to retrieve (all by default)
-
callbackFunctionThe function to call when it's done
- Error The error if an error occurred, null otherwise
- Array The retrieved documents
getIndexes
Syntax
getIndexes
-
collection -
callback
Summary
Gets the list of indexes for a collection.
getStore
Syntax
getStore
-
collection
Summary
Gets an express-session store for this database.
Parameters:
-
collectionStringThe collection to work on
Returns:
An express-session store
increase
Syntax
increase
-
collection -
filter -
data -
callback
Summary
increase values in several documents from collection.
insert
Syntax
insert
-
collection -
data -
callback
Summary
Inserts several documents into a collection.
remove
Syntax
remove
-
collection -
filter -
callback
Summary
Removes several documents from a collection.
removeCollection
Syntax
removeCollection
-
collection -
callback
Summary
Remove a collection from the database
removeProp
Syntax
removeProp
-
collection -
property -
filter -
callback
Summary
Removes a property on all documents in the collection.
renameCollection
Syntax
renameCollection
-
collection -
target -
callback
Summary
Renames a collection.
search
Syntax
search
-
collection -
[criteria] -
[projection] -
[limit] -
[page] -
[sort] -
callback
Summary
Gets an ordered list of documents by page.
Parameters:
-
collectionStringThe collection to work on
-
[criteria]Object optionalMongoDB criterias
-
[projection]Object optionalMongoDB projection
-
[limit]Number optionalThe maximum number of expected documents
-
[page]Number optionalThe expected page
-
[sort]Object optionalA sort object
-
callbackFunctionThe function to call when it's done
- Error The error if an error occurred, null otherwise
- Array The list of documents
- Object Pagination information
update
Syntax
update
-
collection -
filter -
data -
callback
Summary
Updates several documents from collection.