Skip to main content
Module

x/mongo/mod.ts>GridFSBucket

MongoDB driver for Deno
Extremely Popular
Go to Latest
class GridFSBucket
import { GridFSBucket } from "https://deno.land/x/mongo@v0.31.0/mod.ts";

Constructors

new
GridFSBucket(db: Database, options?: GridFSBucketOptions)

Create a new GridFSBucket object on @db with the given @options.

Properties

private
readonly
getBucketData: () => unknown

Methods

delete(id: FileId)

Given a @id, delete this stored file’s files collection document and associated chunks from a GridFS bucket.

downloadToStream(id: FileId, destination: WritableStream<Uint8Array>)

Downloads the contents of the stored file specified by @id and writes the contents to the @destination Stream.

Drops the files and chunks collections associated with this bucket.

find(filter: Filter<File>, options?: GridFSFindOptions): FindCursor<File>

Find and return the files collection documents that match @filter.

openDownloadStream(id: FileId)

Opens a Stream from which the application can read the contents of the stored file specified by @id.

Returns a Stream.

openUploadStream(filename: string, options?: GridFSUploadOptions)

Opens a Stream that the application can write the contents of the file to. The driver generates the file id.

Returns a Stream to which the application will write the contents.

Note: this method is provided for backward compatibility. In languages that use generic type parameters, this method may be omitted since the TFileId type might not be an ObjectId.

openUploadStreamWithId(
id: FileId,
filename: string,
options?: GridFSUploadOptions,
)

Opens a Stream that the application can write the contents of the file to. The application provides a custom file id.

Returns a Stream to which the application will write the contents.

uploadFromStream(
filename: string,
options?: GridFSUploadOptions,
): Promise<ObjectId>

Uploads a user file to a GridFS bucket. The driver generates the file id.

Reads the contents of the user file from the @source Stream and uploads it as chunks in the chunks collection. After all the chunks have been uploaded, it creates a files collection document for @filename in the files collection.

Returns the id of the uploaded file.

Note: this method is provided for backward compatibility. In languages that use generic type parameters, this method may be omitted since the TFileId type might not be an ObjectId.

uploadFromStreamWithId(
id: FileId,
filename: string,
options: GridFSUploadOptions,
): Promise<void>

Uploads a user file to a GridFS bucket. The application supplies a custom file id.

Reads the contents of the user file from the @source Stream and uploads it as chunks in the chunks collection. After all the chunks have been uploaded, it creates a files collection document for @filename in the files collection.

Note: there is no need to return the id of the uploaded file because the application already supplied it as a parameter.