OpenVeo server API for plugins

API Docs for: 3.0.0
Show:

Database

Defined in: lib/Database.js:9
Module: database

Summary

Saves database configuration.

Constructor

Database

Defined in lib/Database.js:9

Syntax

Database

(
  • databaseConf
)

Summary

Parameters:

  • databaseConf Object

    A database configuration object

Example:

// Example for how to use MongoDB database

var api = require('@openveo/api');
var databaseConf = {
 ...
};

// Create a new instance of the database
var db = api.Database.get(databaseConf);

// Prefer using OpenVeo database instance
var db = api.applicationStorage.getDatabase();

Methods

close

Defined in lib/Database.js:80

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

Defined in lib/Database.js:68

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

Defined in lib/Database.js:206

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

Defined in lib/Database.js:155

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

getDatabase

Defined in lib/Database.js:41

Syntax

getDatabase

(
  • databaseConf
)
Database static

Summary

Gets an instance of a Database using the given database configuration.

Parameters:

  • databaseConf Object

    A database configuration object

Returns:

Database:

A Database instance

getIndexes

Defined in lib/Database.js:192

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

Defined in lib/Database.js:221

Syntax

getStore

(
  • collection
)
Store

Summary

Gets an express-session store for the database.

Parameters:

  • collection String

    The collection to work on

Returns:

Store:

An express-session store

increase

Defined in lib/Database.js:232

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

Defined in lib/Database.js:92

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

Defined in lib/Database.js:108

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

Defined in lib/Database.js:262

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

Defined in lib/Database.js:123

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

Defined in lib/Database.js:248

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

Defined in lib/Database.js:139

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