Implements

Constructors

  • Creates an instance of NedbClient.

    Parameters

    • dbName: string

      A unique name for the database.

    • dbDirectoryPath: string

      The folder path for where the database and its collections will be stored.

    • collectionsList: CollectionListEntry[]

      An array of collections, where each item in this array is an object containing the name of the collection and the model or document that the collection will use.

    Returns NedbClient

    BigfootDS

Properties

collections: CollectionAccessor[] = []

A list of meta-objects defining categories of documents in the database.

A collection is an object containing a collection name, document type, plus other properties to help access that data. This means that multiple collections could use the same document type while still keeping database records in separate collections in the database.

BigfootDS

documents: typeof NedbDocument[] = []

The set of document types used in this database.

This is calculated based on the collections that the database is configured to use, since multiple collections could use the same document type.

BigfootDS

embeddedDocuments: typeof NedbEmbeddedDocument[] = []

The set of embedded-document types used in this database.

This is calculated based on the collections that the database is configured to use, since multiple collections could use the same embedded-document type.

BigfootDS

name: string = ""

The name of the database.

BigfootDS

path: string = ""

The database's folder path, where it stores all collections.

BigfootDS

Methods

  • Query a collection and receive a number representing the count of documents matching that query.

    Parameters

    • collectionName: string

      The name of the collection that you wish search through.

    • query: object

      The NeDB query used to find the specific document within the collection.

    Returns Promise<number>

    Integer number of documents within the specified collection that match the query.

    BigfootDS

  • Configure an enforced constraint on a collection.

    See the @seald/nedb documentation for more info about NeDB indexes.

    Parameters

    • collectionName: string

      A string of the collection name to target within the database.

    • indexOptions: EnsureIndexOptions

      An object per the @seald/nedb documentation to configure the index that is to be created.

    Returns Promise<void>

    Promise.

    BigfootDS

  • Create multiple document instances from a provided array of object data, insert each document instance into the database, and return the array of document instances.

    Parameters

    • collectionName: string
    • dataObjectArray: object[]

    Returns Promise<NedbDocument[]>

    BigfootDS

  • Create a document instance from a provided object of data, insert the new document instance into the database, and return the new document instance.

    Parameters

    • collectionName: string
    • dataObject: object

    Returns Promise<NedbDocument>

    BigfootDS

  • Delete collections by model. Can delete multiple collections that use the same model.

    You can also specify whether or not the data within the collection should be deleted, just as a sanity-check. This is enabled by default.

    Parameters

    • model: typeof NedbDocument

      The model to search for.

    • OptionaldeleteData: boolean = true

      Whether or not data within the collection should be deleted. Defaults to true.

    Returns Promise<number>

    The number of collections with a matching name that were deleted.

    BigfootDS

  • Delete collections by name. Can delete multiple collections that use the same name.

    You can also specify whether or not the data within the collection should be deleted, just as a sanity-check. This is enabled by default.

    Parameters

    • name: string

      The name of the collections to search for.

    • OptionaldeleteData: boolean = true

      Whether or not data within the collection should be deleted. Defaults to true.

    Returns Promise<number>

    The number of collections with a matching name that were deleted.

    BigfootDS

  • Delete all documents in all collections within this database. Highly destructive. Could use more work.

    Returns Promise<void>

    BigfootDS

  • Find and delete multiple documents from a specified collection.

    Parameters

    • collectionName: string

      The name of the collection that you wish to search through and modify.

    • query: object

      The NeDB query used to find the specific documents within the collection.

    • options: RemoveOptions = ...

      Options to pass to the query system in NeDB. For this particular method, multi is always set to true.

    Returns Promise<number>

    Number of removed documents.

    BigfootDS

  • Find and delete one document from a specified collection.

    Parameters

    • collectionName: string

      The name of the collection that you wish to search through and modify.

    • query: object

      The NeDB query used to find the specific document within the collection.

    • options: RemoveOptions = ...

      Options to pass to the query system in NeDB. For this particular method, multi is always set to false.

    Returns Promise<number>

    Number of removed documents.

    BigfootDS

  • Search a database for one or more matched documents and modify them, returning the modified documents as an array of document instances.

    If no documents match the given query, this function will return an empty array.

    Parameters

    • collectionName: string

      The name of the database collection to query.

    • query: object

      The query to run to find the relevant document.

    • newData: object

      The data to apply to the found document.

    • Optionaloptions: updateManyOptions

      Optional. The options that can be used in this operation.

    Returns Promise<NedbDocument[]>

    BigfootDS

  • Search a database for one or more matched documents and modify them, returning the modified documents as an array of plain objects.

    If no documents match the given query, this function will return an empty array.

    Parameters

    • collectionName: string

      The name of the database collection to query.

    • query: object

      The query to run to find the relevant document.

    • newData: object

      The data to apply to the found document.

    • Optionaloptions: updateManyOptions

      Optional. The options that can be used in this operation.

    Returns Promise<object[]>

    BigfootDS

  • Search a database for a singular matched document and modify it, returning the modified document as a document instance.

    Parameters

    • collectionName: string

      The name of the database collection to query.

    • query: object

      The query to run to find the relevant document.

    • newData: object

      The data to apply to the found document.

    • Optionaloptions: updateOptions

      Optional. The options that can be used in this operation.

    Returns Promise<null | NedbDocument>

    BigfootDS

  • Search a database for a singular matched document and modify it, returning the modified document as a plain object.

    Parameters

    • collectionName: string

      The name of the database collection to query.

    • query: object

      The query to run to find the relevant document.

    • newData: object

      The data to apply to the found document.

    • Optionaloptions: updateOptions

      Optional. The options that can be used in this operation.

    Returns Promise<null | object>

    BigfootDS

  • Query a collection and return an array of document instances matching that query.

    This method is NOT compatible with NeDB projections.

    Even if nothing matches the given query, an array is returned.

    Parameters

    Returns Promise<NedbDocument[]>

    An instance of the collection's model.

    BigfootDS

  • Query a collection and return an array of objects matching that query, where each object is a document's data.

    This method is compatible with NeDB projections, allowing you to trim the returned data. Read more in the NeDB documentation.

    Even if nothing matches the given query, an array is returned.

    Parameters

    Returns Promise<object[]>

    An instance of the collection's model.

    BigfootDS

  • Query a collection and receive the first document matching that query, returned as a document instance.

    This method is NOT compatible with NeDB projections, and thus returns an instance of the document used by the specified collection.

    Parameters

    Returns Promise<null | NedbDocument>

    An instance of the collection's model.

    BigfootDS

  • Query a collection and receive the first document matching that query, returned as a plain object.

    This method is compatible with NeDB projections, allowing you to trim the returned data. Read more in the NeDB documentation.

    Parameters

    Returns Promise<null | object>

    An instance of the collection's model.

    BigfootDS

  • Retrieve the collection meta object stored on the NeDB client instance matching a given collection name.

    Parameters

    • collectionName: string

      A string of the collection name to target within the database.

    Returns CollectionAccessor

    An object containing helper properties to perform collection-related operations.

    BigfootDS

  • Insert an array of objects of data into the database, following a document schema, and return the saved array of objects of data.

    Parameters

    • collectionName: string

      The name of the collection to insert the data into.

    • dataObjectArray: object[]

      The data to be inserted.

    Returns Promise<object[]>

    The data saved in the database, as an object.

    BigfootDS

  • Insert an object of data into the database, following a document schema, and return the saved object of data.

    Parameters

    • collectionName: string

      The name of the collection to insert the data into.

    • dataObject: object

      The data to be inserted.

    Returns Promise<object>

    The data saved in the database, as an object.

    BigfootDS

  • Remove a collection's index from an array of given field names.

    Parameters

    • collectionName: string

      A string of the collection name to target within the database.

    • fieldNames: string[]

      An array containing one or more fields on the collection that you'd like to remove the index from.

    Returns Promise<void>

    Promise.

    BigfootDS