new GridStore(db, id, filename, mode, options){GridStore}
Create a new GridStore instance
Modes
- "r" - read only. This is the default mode.
- "w" - write in truncate mode. Existing data will be overwritten.
| Name | Type | Description | ||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
db |
Db |
A database instance to interact with. |
||||||||||||||||||||||||||||||||||||||||||||||||
id |
object |
optional
optional unique id for this file |
||||||||||||||||||||||||||||||||||||||||||||||||
filename |
string |
optional
optional filename for this file, no unique constrain on the field |
||||||||||||||||||||||||||||||||||||||||||||||||
mode |
string |
set the mode for this file. |
||||||||||||||||||||||||||||||||||||||||||||||||
options |
object |
optional
Optional settings.
|
- Deprecated
- Use GridFSBucket API instead
Properties:
| Name | Type | Description |
|---|---|---|
chunkSize |
number | Get the gridstore chunk size. |
md5 |
number | The md5 checksum for this file. |
chunkNumber |
number | The current chunk number the gridstore has materialized into memory |
Returns:
GridStore instance.Members
-
staticGridStore.DEFAULT_CONTENT_TYPE
-
Default file mime type
-
staticGridStore.DEFAULT_ROOT_COLLECTION
-
The collection to be used for holding the files and chunks collection.
-
staticGridStore.IO_SEEK_CUR
-
Seek mode where the given length is an offset to the current read/write head.
-
staticGridStore.IO_SEEK_END
-
Seek mode where the given length is an offset to the end of the file.
-
staticGridStore.IO_SEEK_SET
-
Seek mode where the given length is absolute.
Methods
-
staticGridStore.exist(db, name, rootCollection, options, callback){Promise}
-
Checks if a file exists in the database.
Name Type Description dbDb the database to query.
namestring The name of the file to look for.
rootCollectionstring optional The root collection that holds the files and chunks collection. Defaults to {GridStore.DEFAULT_ROOT_COLLECTION}.
optionsobject optional Optional settings.
Name Type Description readPreferenceReadPreference | string optional The preferred read preference (ReadPreference.PRIMARY, ReadPreference.PRIMARY_PREFERRED, ReadPreference.SECONDARY, ReadPreference.SECONDARY_PREFERRED, ReadPreference.NEAREST).
promiseLibraryobject optional A Promise library class the application wishes to use such as Bluebird, must be ES6 compatible
sessionClientSession optional optional session to use for this operation
callbackGridStore~resultCallback optional result from exists.
- Deprecated
- Use GridFSBucket API instead
Returns:
Promise if no callback passed
-
staticGridStore.list(db, rootCollection, options, callback){Promise}
-
Gets the list of files stored in the GridFS.
Name Type Description dbDb the database to query.
rootCollectionstring optional The root collection that holds the files and chunks collection. Defaults to {GridStore.DEFAULT_ROOT_COLLECTION}.
optionsobject optional Optional settings.
Name Type Description readPreferenceReadPreference | string optional The preferred read preference (ReadPreference.PRIMARY, ReadPreference.PRIMARY_PREFERRED, ReadPreference.SECONDARY, ReadPreference.SECONDARY_PREFERRED, ReadPreference.NEAREST).
promiseLibraryobject optional A Promise library class the application wishes to use such as Bluebird, must be ES6 compatible
sessionClientSession optional optional session to use for this operation
callbackGridStore~resultCallback optional result from exists.
- Deprecated
- Use GridFSBucket API instead
Returns:
Promise if no callback passed
-
staticGridStore.read(db, name, length, offset, options, callback){Promise}
-
Reads the contents of a file.
This method has the following signatures
(db, name, callback)
(db, name, length, callback)
(db, name, length, offset, callback)
(db, name, length, offset, options, callback)Name Type Description dbDb the database to query.
namestring The name of the file.
lengthnumber optional The size of data to read.
offsetnumber optional The offset from the head of the file of which to start reading from.
optionsobject optional Optional settings.
Name Type Description readPreferenceReadPreference | string optional The preferred read preference (ReadPreference.PRIMARY, ReadPreference.PRIMARY_PREFERRED, ReadPreference.SECONDARY, ReadPreference.SECONDARY_PREFERRED, ReadPreference.NEAREST).
promiseLibraryobject optional A Promise library class the application wishes to use such as Bluebird, must be ES6 compatible
sessionClientSession optional optional session to use for this operation
callbackGridStore~readCallback optional the command callback.
- Deprecated
- Use GridFSBucket API instead
Returns:
Promise if no callback passed
-
staticGridStore.readlines(db, name, separator, options, callback){Promise}
-
Read the entire file as a list of strings splitting by the provided separator.
Name Type Description dbDb the database to query.
nameString | object the name of the file.
separatorstring optional The character to be recognized as the newline separator.
optionsobject optional Optional settings.
Name Type Description readPreferenceReadPreference | string optional The preferred read preference (ReadPreference.PRIMARY, ReadPreference.PRIMARY_PREFERRED, ReadPreference.SECONDARY, ReadPreference.SECONDARY_PREFERRED, ReadPreference.NEAREST).
promiseLibraryobject optional A Promise library class the application wishes to use such as Bluebird, must be ES6 compatible
sessionClientSession optional optional session to use for this operation
callbackGridStore~readlinesCallback optional the command callback.
- Deprecated
- Use GridFSBucket API instead
Returns:
Promise if no callback passed
-
staticGridStore.unlink(db, names, options, callback){Promise}
-
Deletes the chunks and metadata information of a file from GridFS.
Name Type Description dbDb The database to query.
namesstring | array The name/names of the files to delete.
optionsobject optional Optional settings.
Name Type Description promiseLibraryobject optional A Promise library class the application wishes to use such as Bluebird, must be ES6 compatible
sessionClientSession optional optional session to use for this operation
callbackGridStore~resultCallback optional the command callback.
- Deprecated
- Use GridFSBucket API instead
Returns:
Promise if no callback passed
-
chunkCollection(callback){Collection}
-
Retrieve this file's chunks collection.
Name Type Description callbackGridStore~collectionCallback the command callback.
- Deprecated
- Use GridFSBucket API instead
-
close(options, callback){Promise}
-
Saves this file to the database. This will overwrite the old entry if it
already exists. This will work properly only if mode was initialized to
"w" or "w+".Name Type Description optionsobject optional Optional settings
Name Type Description sessionClientSession optional optional session to use for this operation
callbackGridStore~resultCallback optional this will be called after executing this method. The first parameter will contain null and the second one will contain a reference to this object.
- Deprecated
- Use GridFSBucket API instead
Returns:
Promise if no callback passed
-
collection(callback){Collection}
-
Retrieves the file collection associated with this object.
Name Type Description callbackGridStore~collectionCallback the command callback.
- Deprecated
- Use GridFSBucket API instead
-
destroy()
-
Handles the destroy part of a stream
- Deprecated
- Use GridFSBucket API instead
-
eof(){boolean}
-
Verify if the file is at EOF.
- Deprecated
- Use GridFSBucket API instead
Returns:
if the read/write head is at the end of this file.
-
getc(callback){Promise}
-
Retrieves a single character from this file.
Name Type Description callbackGridStore~resultCallback optional this gets called after this method is executed. Passes null to the first parameter and the character read to the second or null to the second if the read/write head is at the end of the file.
- Deprecated
- Use GridFSBucket API instead
Returns:
Promise if no callback passed
-
open(options, callback){Promise}
-
Opens the file from the database and initialize this object. Also creates a
new one if file does not exist.Name Type Description optionsobject optional Optional settings
Name Type Description sessionClientSession optional optional session to use for this operation
callbackGridStore~openCallback optional this will be called after executing this method
- Deprecated
- Use GridFSBucket API instead
Returns:
Promise if no callback passed
-
puts(string, options, callback){Promise}
-
Writes a string to the file with a newline character appended at the end if
the given string does not have one.Name Type Description stringstring the string to write.
optionsobject optional Optional settings
Name Type Description sessionClientSession optional optional session to use for this operation
callbackGridStore~resultCallback optional this will be called after executing this method. The first parameter will contain null and the second one will contain a reference to this object.
- Deprecated
- Use GridFSBucket API instead
Returns:
Promise if no callback passed
-
read(length, buffer, options, callback){Promise}
-
Retrieves the contents of this file and advances the read/write head. Works with Buffers only.
There are 3 signatures for this method:
(callback)
(length, callback)
(length, buffer, callback)Name Type Description lengthnumber optional the number of characters to read. Reads all the characters from the read/write head to the EOF if not specified.
bufferstring | Buffer optional a string to hold temporary data. This is used for storing the string data read so far when recursively calling this method.
optionsobject optional Optional settings
Name Type Description sessionClientSession optional optional session to use for this operation
callbackGridStore~readCallback optional the command callback.
- Deprecated
- Use GridFSBucket API instead
Returns:
Promise if no callback passed
-
readlines(separator, options, callback){Promise}
-
Read the entire file as a list of strings splitting by the provided separator.
Name Type Description separatorstring optional The character to be recognized as the newline separator.
optionsobject optional Optional settings
Name Type Description sessionClientSession optional optional session to use for this operation
callbackGridStore~readlinesCallback optional the command callback.
- Deprecated
- Use GridFSBucket API instead
Returns:
Promise if no callback passed
-
rewind(options, callback){Promise}
-
Deletes all the chunks of this file in the database if mode was set to "w" or
"w+" and resets the read/write head to the initial position.Name Type Description optionsobject optional Optional settings
Name Type Description sessionClientSession optional optional session to use for this operation
callbackGridStore~resultCallback optional this will be called after executing this method. The first parameter will contain null and the second one will contain a reference to this object.
- Deprecated
- Use GridFSBucket API instead
Returns:
Promise if no callback passed
-
seek(position, seekLocation, options, callback){Promise}
-
Moves the read/write head to a new location.
There are 3 signatures for this method
Seek Location Modes
- GridStore.IO_SEEK_SET, (default) set the position from the start of the file.
- GridStore.IO_SEEK_CUR, set the position from the current position in the file.
- GridStore.IO_SEEK_END, set the position from the end of the file.
Name Type Description positionnumber optional the position to seek to
seekLocationnumber optional seek mode. Use one of the Seek Location modes.
optionsobject optional Optional settings
Name Type Description sessionClientSession optional optional session to use for this operation
callbackGridStore~gridStoreCallback optional the command callback.
- Deprecated
- Use GridFSBucket API instead
Returns:
Promise if no callback passed
-
stream(){GridStoreStream}
-
Return a modified Readable stream including a possible transform method.
- Deprecated
- Use GridFSBucket API instead
-
tell(length, buffer, options, callback){Promise}
-
Retrieves the position of the read/write head of this file.
Name Type Description lengthnumber optional the number of characters to read. Reads all the characters from the read/write head to the EOF if not specified.
bufferstring | Buffer optional a string to hold temporary data. This is used for storing the string data read so far when recursively calling this method.
optionsobject optional Optional settings
Name Type Description sessionClientSession optional optional session to use for this operation
callbackGridStore~tellCallback optional the command callback.
- Deprecated
- Use GridFSBucket API instead
Returns:
Promise if no callback passed
-
unlink(options, callback){Promise}
-
Deletes all the chunks of this file in the database.
Name Type Description optionsobject optional Optional settings
Name Type Description sessionClientSession optional optional session to use for this operation
callbackGridStore~resultCallback optional the command callback.
- Deprecated
- Use GridFSBucket API instead
Returns:
Promise if no callback passed
-
write(data, close, options, callback){Promise}
-
Writes some data. This method will work properly only if initialized with mode "w" or "w+".
Name Type Description datastring | Buffer the data to write.
closeboolean optional closes this file after writing if set to true.
optionsobject optional Optional settings
Name Type Description sessionClientSession optional optional session to use for this operation
callbackGridStore~resultCallback optional this will be called after executing this method. The first parameter will contain null and the second one will contain a reference to this object.
- Deprecated
- Use GridFSBucket API instead
Returns:
Promise if no callback passed
-
writeFile(file, options, callback){Promise}
-
Stores a file from the file system to the GridFS database.
Name Type Description filestring | Buffer | FileHandle the file to store.
optionsobject optional Optional settings
Name Type Description sessionClientSession optional optional session to use for this operation
callbackGridStore~resultCallback optional this will be called after executing this method. The first parameter will contain null and the second one will contain a reference to this object.
- Deprecated
- Use GridFSBucket API instead
Returns:
Promise if no callback passed
Type Definitions
-
collectionCallback(error, collection)
-
The collection callback format.
Name Type Description errorMongoError An error instance representing the error during the execution.
collectionCollection The collection from the command execution.
-
gridStoreCallback(error, gridStore)
-
The tell callback format.
Name Type Description errorMongoError An error instance representing the error during the execution.
gridStoreGridStore The gridStore.
-
openCallback(error, gridStore)
-
The callback format for the Gridstore.open method
Name Type Description errorMongoError An error instance representing the error during the execution.
gridStoreGridStore The GridStore instance if the open method was successful.
-
readCallback(error, data)
-
The read callback format.
Name Type Description errorMongoError An error instance representing the error during the execution.
dataBuffer The data read from the GridStore object
-
readlinesCallback(error, strings)
-
The readlines callback format.
Name Type Description errorMongoError An error instance representing the error during the execution.
stringsArray.<string> The array of strings returned.
-
resultCallback(options, error, result)
-
The callback result format.
Name Type Description optionsobject optional Optional settings
Name Type Description sessionClientSession optional optional session to use for this operation
errorMongoError An error instance representing the error during the execution.
resultobject The result from the callback.
-
tellCallback(error, position)
-
The tell callback format.
Name Type Description errorMongoError An error instance representing the error during the execution.
positionnumber The current read position in the GridStore.