new GridFSBucket(db, options){GridFSBucket}
Constructor for a streaming GridFS interface
| Name | Type | Default | Description | ||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
db |
Db |
A db handle |
|||||||||||||||||||||
options |
object | null |
optional
Optional settings.
|
Fires:
- GridFSBucketWriteStream#event:index
Methods
-
delete(id, callback)
-
Deletes a file with the given id
Name Type Description idObjectId The id of the file doc
callbackGridFSBucket~errorCallback optional -
drop(callback)
-
Removes this bucket's files collection, followed by its chunks collection.
Name Type Description callbackGridFSBucket~errorCallback optional -
find(filter, options){Cursor}
-
Convenience wrapper around find on the files collection
Name Type Default Description filterObject optionsObject null optional Optional settings for cursor
Name Type Default Description batchSizenumber null optional Optional batch size for cursor
limitnumber null optional Optional limit for cursor
maxTimeMSnumber null optional Optional maxTimeMS for cursor
noCursorTimeoutboolean null optional Optionally set cursor's
noCursorTimeoutflagskipnumber null optional Optional skip for cursor
sortobject null optional Optional sort for cursor
-
openDownloadStream(id, options){GridFSBucketReadStream}
-
Returns a readable stream (GridFSBucketReadStream) for streaming file
data from GridFS.Name Type Default Description idObjectId The id of the file doc
optionsObject null optional Optional settings.
Name Type Default Description startNumber null optional Optional 0-based offset in bytes to start streaming from
endNumber null optional Optional 0-based offset in bytes to stop streaming before
-
openDownloadStreamByName(filename, options){GridFSBucketReadStream}
-
Returns a readable stream (GridFSBucketReadStream) for streaming the
file with the given name from GridFS. If there are multiple files with
the same name, this will stream the most recent file with the given name
(as determined by theuploadDatefield). You can set therevision
option to change this behavior.Name Type Default Description filenameString The name of the file to stream
optionsObject null optional Optional settings
Name Type Default Description revisionnumber -1 optional The revision number relative to the oldest file with the given filename. 0 gets you the oldest file, 1 gets you the 2nd oldest, -1 gets you the newest.
startNumber null optional Optional 0-based offset in bytes to start streaming from
endNumber null optional Optional 0-based offset in bytes to stop streaming before
-
openUploadStream(filename, options){GridFSBucketWriteStream}
-
Returns a writable stream (GridFSBucketWriteStream) for writing
buffers to GridFS. The stream's 'id' property contains the resulting
file's id.Name Type Default Description filenamestring The value of the 'filename' key in the files doc
optionsobject null optional Optional settings.
Name Type Default Description chunkSizeBytesnumber null optional Optional overwrite this bucket's chunkSizeBytes for this file
metadataobject null optional Optional object to store in the file document's
metadatafieldcontentTypestring null optional Optional string to store in the file document's
contentTypefieldaliasesarray null optional Optional array of strings to store in the file document's
aliasesfield -
openUploadStreamWithId(id, filename, options){GridFSBucketWriteStream}
-
Returns a writable stream (GridFSBucketWriteStream) for writing
buffers to GridFS for a custom file id. The stream's 'id' property contains the resulting
file's id.Name Type Default Description idstring | number | object A custom id used to identify the file
filenamestring The value of the 'filename' key in the files doc
optionsobject null optional Optional settings.
Name Type Default Description chunkSizeBytesnumber null optional Optional overwrite this bucket's chunkSizeBytes for this file
metadataobject null optional Optional object to store in the file document's
metadatafieldcontentTypestring null optional Optional string to store in the file document's
contentTypefieldaliasesarray null optional Optional array of strings to store in the file document's
aliasesfield -
rename(id, filename, callback)
-
Renames the file with the given _id to the given string
Name Type Description idObjectId the id of the file to rename
filenameString new name for the file
callbackGridFSBucket~errorCallback optional
Type Definitions
-
errorCallback(error)
-
Callback format for all GridFSBucket methods that can accept a callback.
Name Type Description errorMongoError An error instance representing any errors that occurred
Events
-
When the first call to openUploadStream is made, the upload stream will
check to see if it needs to create the proper indexes on the chunks and
files collections. This event is fired either when 1) it determines that
no index creation is necessary, 2) when it successfully creates the
necessary indexes.Type:
- Error