Skip to main content
Deno 2 is finally here 🎉️
Learn more
Very Popular
Latest
class Collection
import { Collection } from "https://deno.land/x/mongo@v0.33.0/src/collection/collection.ts";

A collection within a MongoDB Database

Constructors

new
Collection(
protocol: WireProtocol,
dbName: string,
name: string,
)

Methods

aggregate<U = T>(pipeline: AggregatePipeline<U>[], options?: AggregateOptions): AggregateCursor<U>

Perform aggregation on the collection

countDocuments(filter?: Filter<T>, options?: CountOptions): Promise<number>

Count the number of documents matching the given filter

createIndexes(options: CreateIndexOptions): Promise<{ ok: number; createdCollectionAutomatically: boolean; numIndexesBefore: number; numIndexesAfter: number; }>

Create an index on the collection

deleteMany(filter: Filter<T>, options?: DeleteOptions): Promise<number>

Delete multiple documents matching the given filter

deleteOne(filter: Filter<T>, options?: DeleteOptions): Promise<number>

Delete a single document matching the given filter

distinct(
key: string,
query?: Filter<T>,
options?: DistinctOptions,
): Promise<any>
drop(options?: DropOptions): Promise<void>

Drop the collection from the database

dropIndexes(options: DropIndexOptions): Promise<{ ok: number; nIndexesWas: number; }>

Drop an index from the collection

estimatedDocumentCount(): Promise<number>

A function that returns the estimated number of documents in the collection

find(filter?: Filter<T>, options?: FindOptions): FindCursor<T>

Get a FindCursor for the given filter

findAndModify(filter?: Filter<T>, options?: FindAndModifyOptions<T>): Promise<T | null>

Find and modify a document in one, returning the matching document.

findOne(filter?: Filter<T>, options?: FindOptions): Promise<T | undefined>

Find one Document using the given filter

insertMany(docs: InsertDocument<T>[], options?: InsertOptions): Promise<{ insertedIds: Required<InsertDocument<T>>["_id"][]; insertedCount: number; }>

Insert multiple documents into the collection

insertOne(doc: InsertDocument<T>, options?: InsertOptions): Promise<Required<InsertDocument<T>>["_id"]>

Insert a single document into the collection

listIndexes(): ListIndexesCursor<{ v: number; key: Document; name: string; ns?: string; }>

List the indexes on the collection

replaceOne(
filter: Filter<T>,
replacement: InsertDocument<T>,
options?: UpdateOptions,
): Promise<{ upsertedId: ObjectId | undefined; upsertedCount: number; matchedCount: number; modifiedCount: number; }>

Replace a single document matching the given filter

updateMany(
filter: Filter<T>,
options?: UpdateOptions,
): Promise<{ upsertedIds: ObjectId[] | undefined; upsertedCount: number; modifiedCount: number; matchedCount: number; }>

Update multiple documents matching the given filter

updateOne(
filter: Filter<T>,
update: UpdateFilter<T>,
options?: UpdateOptions,
): Promise<{ upsertedId: ObjectId | undefined; upsertedCount: number; matchedCount: number; modifiedCount: number; }>

Update a single document matching the given filter