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 overwriten.
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 db
Db the database to query.
name
string The name of the file to look for.
rootCollection
string optional The root collection that holds the files and chunks collection. Defaults to {GridStore.DEFAULT_ROOT_COLLECTION}.
options
object optional Optional settings.
Name Type Description readPreference
ReadPreference | string optional The preferred read preference (ReadPreference.PRIMARY, ReadPreference.PRIMARY_PREFERRED, ReadPreference.SECONDARY, ReadPreference.SECONDARY_PREFERRED, ReadPreference.NEAREST).
promiseLibrary
object optional A Promise library class the application wishes to use such as Bluebird, must be ES6 compatible
session
ClientSession optional optional session to use for this operation
callback
GridStore~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 db
Db the database to query.
rootCollection
string optional The root collection that holds the files and chunks collection. Defaults to {GridStore.DEFAULT_ROOT_COLLECTION}.
options
object optional Optional settings.
Name Type Description readPreference
ReadPreference | string optional The preferred read preference (ReadPreference.PRIMARY, ReadPreference.PRIMARY_PREFERRED, ReadPreference.SECONDARY, ReadPreference.SECONDARY_PREFERRED, ReadPreference.NEAREST).
promiseLibrary
object optional A Promise library class the application wishes to use such as Bluebird, must be ES6 compatible
session
ClientSession optional optional session to use for this operation
callback
GridStore~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 db
Db the database to query.
name
string The name of the file.
length
number optional The size of data to read.
offset
number optional The offset from the head of the file of which to start reading from.
options
object optional Optional settings.
Name Type Description readPreference
ReadPreference | string optional The preferred read preference (ReadPreference.PRIMARY, ReadPreference.PRIMARY_PREFERRED, ReadPreference.SECONDARY, ReadPreference.SECONDARY_PREFERRED, ReadPreference.NEAREST).
promiseLibrary
object optional A Promise library class the application wishes to use such as Bluebird, must be ES6 compatible
session
ClientSession optional optional session to use for this operation
callback
GridStore~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 db
Db the database to query.
name
String | object the name of the file.
separator
string optional The character to be recognized as the newline separator.
options
object optional Optional settings.
Name Type Description readPreference
ReadPreference | string optional The preferred read preference (ReadPreference.PRIMARY, ReadPreference.PRIMARY_PREFERRED, ReadPreference.SECONDARY, ReadPreference.SECONDARY_PREFERRED, ReadPreference.NEAREST).
promiseLibrary
object optional A Promise library class the application wishes to use such as Bluebird, must be ES6 compatible
session
ClientSession optional optional session to use for this operation
callback
GridStore~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 db
Db The database to query.
names
string | array The name/names of the files to delete.
options
object optional Optional settings.
Name Type Description promiseLibrary
object optional A Promise library class the application wishes to use such as Bluebird, must be ES6 compatible
session
ClientSession optional optional session to use for this operation
callback
GridStore~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 callback
GridStore~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 options
object optional Optional settings
Name Type Description session
ClientSession optional optional session to use for this operation
callback
GridStore~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 callback
GridStore~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 callback
GridStore~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 options
object optional Optional settings
Name Type Description session
ClientSession optional optional session to use for this operation
callback
GridStore~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 string
string the string to write.
options
object optional Optional settings
Name Type Description session
ClientSession optional optional session to use for this operation
callback
GridStore~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 length
number optional the number of characters to read. Reads all the characters from the read/write head to the EOF if not specified.
buffer
string | Buffer optional a string to hold temporary data. This is used for storing the string data read so far when recursively calling this method.
options
object optional Optional settings
Name Type Description session
ClientSession optional optional session to use for this operation
callback
GridStore~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 separator
string optional The character to be recognized as the newline separator.
options
object optional Optional settings
Name Type Description session
ClientSession optional optional session to use for this operation
callback
GridStore~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 options
object optional Optional settings
Name Type Description session
ClientSession optional optional session to use for this operation
callback
GridStore~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 position
number optional the position to seek to
seekLocation
number optional seek mode. Use one of the Seek Location modes.
options
object optional Optional settings
Name Type Description session
ClientSession optional optional session to use for this operation
callback
GridStore~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 length
number optional the number of characters to read. Reads all the characters from the read/write head to the EOF if not specified.
buffer
string | Buffer optional a string to hold temporary data. This is used for storing the string data read so far when recursively calling this method.
options
object optional Optional settings
Name Type Description session
ClientSession optional optional session to use for this operation
callback
GridStore~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 options
object optional Optional settings
Name Type Description session
ClientSession optional optional session to use for this operation
callback
GridStore~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 data
string | Buffer the data to write.
close
boolean optional closes this file after writing if set to true.
options
object optional Optional settings
Name Type Description session
ClientSession optional optional session to use for this operation
callback
GridStore~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 file
string | Buffer | FileHandle the file to store.
options
object optional Optional settings
Name Type Description session
ClientSession optional optional session to use for this operation
callback
GridStore~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 error
MongoError An error instance representing the error during the execution.
collection
Collection The collection from the command execution.
-
gridStoreCallback(error, gridStore)
-
The tell callback format.
Name Type Description error
MongoError An error instance representing the error during the execution.
gridStore
GridStore The gridStore.
-
openCallback(error, gridStore)
-
The callback format for the Gridstore.open method
Name Type Description error
MongoError An error instance representing the error during the execution.
gridStore
GridStore The GridStore instance if the open method was successful.
-
readCallback(error, data)
-
The read callback format.
Name Type Description error
MongoError An error instance representing the error during the execution.
data
Buffer The data read from the GridStore object
-
readlinesCallback(error, strings)
-
The readlines callback format.
Name Type Description error
MongoError An error instance representing the error during the execution.
strings
Array.<string> The array of strings returned.
-
resultCallback(options, error, result)
-
The callback result format.
Name Type Description options
object optional Optional settings
Name Type Description session
ClientSession optional optional session to use for this operation
error
MongoError An error instance representing the error during the execution.
result
object The result from the callback.
-
tellCallback(error, position)
-
The tell callback format.
Name Type Description error
MongoError An error instance representing the error during the execution.
position
number The current read position in the GridStore.