new GridFSBucket(db, options){GridFSBucket}
Constructor for a streaming GridFS interface
| Name | Type | Description | ||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
db |
Db |
A db handle |
||||||||||||||||||||
options |
object |
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 Description filterObject optionsObject optional Optional settings for cursor
Name Type Description batchSizenumber optional Optional batch size for cursor
limitnumber optional Optional limit for cursor
maxTimeMSnumber optional Optional maxTimeMS for cursor
noCursorTimeoutboolean optional Optionally set cursor's
noCursorTimeoutflagskipnumber optional Optional skip for cursor
sortobject optional Optional sort for cursor
-
openDownloadStream(id, options){GridFSBucketReadStream}
-
Returns a readable stream (GridFSBucketReadStream) for streaming file
data from GridFS.Name Type Description idObjectId The id of the file doc
optionsObject optional Optional settings.
Name Type Description startNumber optional Optional 0-based offset in bytes to start streaming from
endNumber 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 Description filenameString The name of the file to stream
optionsObject 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 optional Optional 0-based offset in bytes to start streaming from
endNumber 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 Description filenamestring The value of the 'filename' key in the files doc
optionsobject optional Optional settings.
Name Type Default Description chunkSizeBytesnumber optional Optional overwrite this bucket's chunkSizeBytes for this file
metadataobject optional Optional object to store in the file document's
metadatafieldcontentTypestring optional Optional string to store in the file document's
contentTypefieldaliasesarray optional Optional array of strings to store in the file document's
aliasesfielddisableMD5boolean false optional If true, disables adding an md5 field to file data
-
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 Description idstring | number | object A custom id used to identify the file
filenamestring The value of the 'filename' key in the files doc
optionsobject optional Optional settings.
Name Type Default Description chunkSizeBytesnumber optional Optional overwrite this bucket's chunkSizeBytes for this file
metadataobject optional Optional object to store in the file document's
metadatafieldcontentTypestring optional Optional string to store in the file document's
contentTypefieldaliasesarray optional Optional array of strings to store in the file document's
aliasesfielddisableMD5boolean false optional If true, disables adding an md5 field to file data
-
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