S

Loading…

Class

SinterCollection

A collection of documents, typed by TDocument.

Get one from SinterDatabase.collection. The type parameter makes filters, updates and results type-checked against your document shape; it is not enforced by the server.

class SinterCollection<TDocument extends object = Document>

Defined in packages/driver/src/collection.ts:138

Constructors#

Properties#

Accessors#

Methods#

M

aggregate

#
aggregate<TResult extends object = Document>(
  pipeline: readonly AggregationStage<TDocument>[],
  options?: AggregateOptions,
): AggregateCursor<TResult>

Starts an aggregation and returns a cursor. No request is sent until the cursor is read. See AggregationStage for the stages.

The result type is not worked out from the pipeline: pass it as the type argument when you need it, such as aggregate<{ total: number }>(...).

Example

const [{ total }] = await users
  .aggregate<{ total: number }>([
    { $match: { active: true } },
    { $count: "total" },
  ])
  .toArray();

Defined in packages/driver/src/collection.ts:471

M

countDocuments

#
countDocuments(
  filter?: Filter<TDocument>,
  options?: QueryBudgetOptions,
): Promise<number>

Counts the documents that match the filter, on the server, without transferring them. Without a filter it counts the whole collection. A collection that does not exist has no documents.

Defined in packages/driver/src/collection.ts:248

M

distinct

#
distinct<TField extends string>(
  field: TField,
  filter?: Filter<TDocument>,
  options?: QueryBudgetOptions,
): Promise<DistinctValue<TDocument, TField>[]>

Returns the distinct values of a field among the documents that match the filter, in the order described in docs/query-semantics.md.

A field that holds an array contributes its elements, and a document without the field contributes nothing. Values are distinct by exact equality, so 1 and 1n are two values.

Defined in packages/driver/src/collection.ts:277

M

estimatedDocumentCount

#
estimatedDocumentCount(): Promise<number>

Counts every document in the collection. It needs no scan: the server answers from the size of the collection.

Defined in packages/driver/src/collection.ts:265

M

find

#
find<const TProjection extends Projection<TDocument> | undefined = undefined>(
  filter?: Filter<TDocument>,
  options?: FindOptions<TDocument, TProjection>,
): FindCursor<TDocument, ProjectedDocument<TDocument, TProjection>>

Starts a query and returns a cursor. No request is sent until the cursor is read.

The cursor can be read with next(), collected with toArray(), or iterated with for await. Always finish or close() it so the server can release it.

Defined in packages/driver/src/collection.ts:431

M

replaceOne

#
replaceOne(
  filter: Filter<TDocument>,
  replacement: OptionalId<TDocument>,
  options?: UpdateOptions,
): Promise<UpdateResult>

Replaces the first matching document with replacement.

The document keeps its _id. Giving the replacement a different _id fails with an ImmutableId server error. With upsert, a replacement is inserted when nothing matches.

Defined in packages/driver/src/collection.ts:309

M

updateMany

#
updateMany(
  filter: Filter<TDocument>,
  update: UpdateFilter<TDocument>,
  options?: UpdateOptions,
): Promise<UpdateResult>

Applies an update to every matching document.

With upsert, a document seeded from the equality terms of the filter is inserted, updated, and reported in upsertedId when nothing matches.

Returns Promise<UpdateResult>

modifiedCount counts only documents whose stored bytes actually changed.

Defined in packages/driver/src/collection.ts:354

M

updateOne

#
updateOne(
  filter: Filter<TDocument>,
  update: UpdateFilter<TDocument>,
  options?: UpdateOptions,
): Promise<UpdateResult>

Applies an update to the first matching document.

With upsert, a document seeded from the equality terms of the filter is inserted, updated, and reported in upsertedId when nothing matches.

Returns Promise<UpdateResult>

modifiedCount counts only documents whose stored bytes actually changed.

Defined in packages/driver/src/collection.ts:337

Used by#