OpenVeo server API for plugins

API Docs for: 7.0.0
Show:

MongoDatabase

Summary

Defines a MongoDB Database.

Constructor

MongoDatabase

Syntax

MongoDatabase

(
  • configuration
)

Summary

Parameters:

  • configuration Object

    A database configuration object

    • host String

      MongoDB server host

    • port Number

      MongoDB server port

    • database String

      The name of the database

    • username String

      The name of the database user

    • password String

      The password of the database user

    • [replicaSet] String optional

      The name of the ReplicaSet

    • [seedlist] String optional

      The comma separated list of secondary servers

Methods

add

Syntax

add

(
  • collection
  • documents
  • callback
)
async

Summary

Inserts several documents into a collection.

Parameters:

  • collection String

    The collection to work on

  • documents 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 The list of inserted documents

buildFields

Syntax

buildFields

(
  • fields
  • doesInclude
)
Object static

Summary

Builds MongoDb fields projection.

Parameters:

  • fields Array

    The list of fields to include or exclude

  • doesInclude Boolean

    true to include fields and exclude all other fields or false to exclude fields and include all other fields

Returns:

Object:

The MongoDB projection description object

buildFilter

Syntax

buildFilter

(
  • resourceFilter
)
Object static

Summary

Builds MongoDb filter from a ResourceFilter.

Parameters:

Returns:

Object:

The MongoDB like filter description object

buildSort

Syntax

buildSort

(
  • [sort]
)
Object static

Summary

Builds MongoDB sort object.

Concretely it just replaces "score" by "{ $meta: 'textScore' }", "asc" by 1 and "desc" by -1.

Parameters:

  • [sort] Object optional

    The 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:

Object:

The MongoDB sort description object

close

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

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

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

dropIndex

Syntax

dropIndex

(
  • collection
  • indexName
  • callback
)
async

Summary

Drops an index from a collection.

Parameters:

  • collection String

    The collection to work on

  • indexName Array

    The name of the index to drop

  • 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

Syntax

get

(
  • collection
  • [filter]
  • [fields]
  • [limit]
  • [page]
  • sort
  • callback
)
async

Summary

Fetches documents from the collection.

Parameters:

  • collection String

    The collection to work on

  • [filter] ResourceFilter optional

    Rules to filter documents

  • [fields] Object optional

    Expected 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

    • [include] Array optional

      The list of fields to include in the response, all other fields are excluded

    • [exclude] Array optional

      The list of fields to exclude from response, all other fields are included. Ignored if include is also specified.

  • [limit] Number optional

    A limit number of documents to retrieve (10 by default)

  • [page] Number optional

    The page number started at 0 for the first page

  • sort Object

    The 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 Function

    The 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
)
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

getOne

Syntax

getOne

(
  • collection
  • [filter]
  • [fields]
  • callback
)
async

Summary

Fetches a single document from the storage.

Parameters:

  • collection String

    The collection to work on

  • [filter] ResourceFilter optional

    Rules to filter documents

  • [fields] Object optional

    Expected 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

    • [include] Array optional

      The list of fields to include in the response, all other fields are excluded

    • [exclude] Array optional

      The list of fields to exclude from response, all other fields are included. Ignored if include is also specified.

  • callback Function

    The function to call when it's done

    • Error The error if an error occurred, null otherwise
    • Object The document

getStore

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

remove

Syntax

remove

(
  • collection
  • [filter]
  • callback
)
async

Summary

Removes several documents from a collection.

Parameters:

  • collection String

    The collection to work on

  • [filter] ResourceFilter optional

    Rules to filter documents to remove

  • 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

Syntax

removeCollection

(
  • collection
  • callback
)
async

Summary

Removes 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

removeField

Syntax

removeField

(
  • collection
  • property
  • [filter]
  • callback
)
async

Summary

Removes a property from documents of a collection.

Parameters:

  • collection String

    The collection to work on

  • property String

    The name of the property to remove

  • [filter] ResourceFilter optional

    Rules to filter documents to update

  • 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

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

updateOne

Syntax

updateOne

(
  • collection
  • [filter]
  • data
  • callback
)
async

Summary

Updates a document from collection.

Parameters:

  • collection String

    The collection to work on

  • [filter] ResourceFilter optional

    Rules to filter the document to update

  • data Object

    The modifications to perform

  • callback Function

    The 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.

configuration

Syntax

configuration

Object final

Summary

The storage configuration.

database

Syntax

database

Db final

Summary

The connected database.

host

Syntax

host

String final

Summary

Database host.

name

Syntax

name

String final

Summary

Database name.

password

Syntax

password

String final

Summary

Database user password.

port

Syntax

port

Number final

Summary

Database port.

replicaSet

Syntax

replicaSet

String final

Summary

The name of the replica set.

seedlist

Syntax

seedlist

String final

Summary

A comma separated list of secondary servers.

username

Syntax

username

String final

Summary

Database user name.