OpenVeo server API for plugins

API Docs for: 3.0.0
Show:

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:

  • Object Object

    databaseConf 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);

Methods

close

Inherited from Database but overwritten in lib/database/mongodb/MongoDatabase.js:86

Syntax

close

(
  • callback
)
async

Summary

Closes connection to the database.

Parameters:

  • callback Function

    The function to call when connection is closed

    • Error The error if an error occurred, null otherwise

connect

Inherited from Database but overwritten in lib/database/mongodb/MongoDatabase.js:51

Syntax

connect

(
  • callback
)
async

Summary

Establishes connection to the database.

Parameters:

  • callback Function

    The function to call when connection to the database is established

    • Error The error if an error occurred, null otherwise

createIndexes

Inherited from Database but overwritten in lib/database/mongodb/MongoDatabase.js:309

Syntax

createIndexes

(
  • collection
  • indexes
  • callback
)
async

Summary

Creates indexes for a collection.

Parameters:

  • collection String

    The collection to work on

  • indexes Array

    A list of indexes using MongoDB format

  • callback Function

    The function to call when it's done

    • Error The error if an error occurred, null otherwise
    • Object Information about the operation

get

Inherited from Database but overwritten in lib/database/mongodb/MongoDatabase.js:211

Syntax

get

(
  • collection
  • [criteria]
  • [projection]
  • [limit]
  • callback
)
async

Summary

Gets a list of documents.

Parameters:

  • collection String

    The collection to work on

  • [criteria] Object optional

    MongoDB criterias

  • [projection] Object optional

    MongoDB projection

  • [limit] Number optional

    A limit number of items to retrieve (all by default)

  • callback Function

    The function to call when it's done

    • Error The error if an error occurred, null otherwise
    • Array The retrieved documents

getIndexes

Inherited from Database but overwritten in lib/database/mongodb/MongoDatabase.js:290

Syntax

getIndexes

(
  • collection
  • callback
)
async

Summary

Gets the list of indexes for a collection.

Parameters:

  • collection String

    The collection to work on

  • callback Function

    The function to call when it's done

    • Error The error if an error occurred, null otherwise
    • Array The list of indexes

getStore

Inherited from Database but overwritten in lib/database/mongodb/MongoDatabase.js:329

Syntax

getStore

(
  • collection
)
Store

Summary

Gets an express-session store for this database.

Parameters:

  • collection String

    The collection to work on

Returns:

Store:

An express-session store

increase

Inherited from Database but overwritten in lib/database/mongodb/MongoDatabase.js:341

Syntax

increase

(
  • collection
  • filter
  • data
  • callback
)
async

Summary

increase values in several documents from collection.

Parameters:

  • collection String

    The collection to work on

  • filter Object

    Filters formatted like MongoDB filters

  • data Object

    Document data

  • callback Function

    The function to call when it's done

    • Error The error if an error occurred, null otherwise
    • Number The number of increased documents

insert

Inherited from Database but overwritten in lib/database/mongodb/MongoDatabase.js:98

Syntax

insert

(
  • collection
  • data
  • callback
)
async

Summary

Inserts several documents into a collection.

Parameters:

  • collection String

    The collection to work on

  • data Array

    Document(s) to insert into the collection

  • callback Function

    The function to call when it's done

    • Error The error if an error occurred, null otherwise
    • Number The total amount of documents inserted
    • Array All the documents inserted

remove

Inherited from Database but overwritten in lib/database/mongodb/MongoDatabase.js:124

Syntax

remove

(
  • collection
  • filter
  • callback
)
async

Summary

Removes several documents from a collection.

Parameters:

  • collection String

    The collection to work on

  • filter Object

    Filters formatted like MongoDB filters

  • callback Function

    The function to call when it's done

    • Error The error if an error occurred, null otherwise
    • Number The number of deleted documents

removeCollection

Inherited from Database but overwritten in lib/database/mongodb/MongoDatabase.js:395

Syntax

removeCollection

(
  • collection
  • callback
)
async

Summary

Remove a collection from the database

Parameters:

  • collection String

    The collection to work on

  • callback Function

    The function to call when it's done

    • Error The error if an error occurred, null otherwise

removeProp

Inherited from Database but overwritten in lib/database/mongodb/MongoDatabase.js:149

Syntax

removeProp

(
  • collection
  • property
  • filter
  • callback
)
async

Summary

Removes a property on all documents in the collection.

Parameters:

  • collection String

    The collection to work on

  • property String

    The property name to remove

  • filter Object

    Filters formatted like MongoDB filters

  • callback Function

    The function to call when it's done

    • Error The error if an error occurred, null otherwise
    • Number The number of updated documents

renameCollection

Inherited from Database but overwritten in lib/database/mongodb/MongoDatabase.js:369

Syntax

renameCollection

(
  • collection
  • target
  • callback
)
async

Summary

Renames a collection.

Parameters:

  • collection String

    The collection to work on

  • target String

    The new name of the collection

  • callback Function

    The function to call when it's done

    • Error The error if an error occurred, null otherwise

update

Inherited from Database but overwritten in lib/database/mongodb/MongoDatabase.js:183

Syntax

update

(
  • collection
  • filter
  • data
  • callback
)
async

Summary

Updates several documents from collection.

Parameters:

  • collection String

    The collection to work on

  • filter Object

    Filters formatted like MongoDB filters

  • data Object

    Document data

  • callback Function

    The function to call when it's done

    • Error The error if an error occurred, null otherwise
    • Number The number of updated documents