Collections

Operations on collections

Overview

Collection operations

Tashmet collections support a subset of operations from MongoDB.

insertOne

insertOne(
  document: OptionalId<TSchema>, options?: InsertOneOptions
): Promise<InsertOneResult>

Inserts a single document into the collection. If documents passed in do not contain the _id field, one will be added to each of the documents missing it by the driver, mutating the document. This behavior can be overridden by setting the forceServerObjectId flag.

  • doc - The document to insert

  • options - Optional settings for the command

See: https://www.mongodb.com/docs/drivers/node/current/usage-examples/insertOne/


insertMany

insertMany(
  documents: OptionalId<TSchema>[], options?: BulkWriteOptions
): Promise<InsertManyResult>

Inserts an array of documents into the collection. If documents passed in do not contain the _id field, one will be added to each of the documents missing it by the driver, mutating the document. This behavior can be overridden by setting the forceServerObjectId flag.

  • docs - The documents to insert

  • options - Optional settings for the command

See: https://www.mongodb.com/docs/drivers/node/current/usage-examples/insertMany/


findOne

Fetches the first document that matches the filter

  • filter - Query for find Operation

  • options - Optional settings for the command

See: https://www.mongodb.com/docs/drivers/node/current/usage-examples/findOne/


find

Creates a cursor for a filter that can be used to iterate over results from the collection

  • filter - The filter predicate. If unspecified, then all documents in the collection will match the predicate

  • options - Optional settings for the command

    • sort?: SortingMap - Set to sort the documents coming back from the query. Key-value map, ex. {a: 1, b: -1}

    • skip?: number - Skip the first number of documents from the results.

    • limit?: number - Limit the number of items that are fetched.

    • projection?: Projection<TSchema> - The fields to return in the query. Object of fields to either include or exclude (one of, not both), {'a':1, 'b': 1} or {'a': 0, 'b': 0}

See: https://www.mongodb.com/docs/drivers/node/current/usage-examples/find/


aggregate

Execute an aggregation framework pipeline against the collection

  • pipeline - An array of aggregation pipelines to execute

  • options - Optional settings for the command

    • batchSize?: number - The number of documents to return per batch. See aggregation documentation.

    • bypassDocumentValidation?: boolean - Allow driver to bypass schema validation

    • collation?: CollationOptions - Specify collation.

    • out?: string

See: https://www.mongodb.com/docs/drivers/node/current/usage-examples/aggregate/


distinct

The distinct command returns a list of distinct values for the given key across a collection.


countDocuments

Gets the number of documents matching the filter.

  • filter - The filter for the count

  • options - Optional settings for the command


replaceOne

Replace a document in a collection with another document


updateOne

updateMany

deleteOne

Delete a document from a collection

  • filter - The filter used to select the document to remove

  • options - Optional settings for the command


deleteMany

Last updated

Was this helpful?