<inputtype="search"id="api-filter"placeholder="Type to filter APIs">
</div>
<divid="api-tabview-panel">
<ulid="api-classes"class="apis classes">
<li><ahref="../classes/Represents a
Replicaset Configuration.html">Represents a
Replicaset Configuration</a></li>
<li><ahref="../classes/Represents a BatchWriteResult.html">Represents a BatchWriteResult</a></li>
<li><ahref="../classes/Represents a Collection.html">Represents a Collection</a></li>
<li><ahref="../classes/Represents a Cursor..html">Represents a Cursor.</a></li>
<li><ahref="../classes/Represents a CursorStream..html">Represents a CursorStream.</a></li>
<li><ahref="../classes/Represents a Db.html">Represents a Db</a></li>
<li><ahref="../classes/Represents a GridFS File Stream..html">Represents a GridFS File Stream.</a></li>
<li><ahref="../classes/.html"></a></li>
<li><ahref="../classes/Represents a MongoClient.html">Represents a MongoClient</a></li>
<li><ahref="../classes/Represents a Mongos connection with failover to backup proxies.html">Represents a Mongos connection with failover to backup proxies</a></li>
<li><ahref="../classes/Represents a OrderedBulkOperation.html">Represents a OrderedBulkOperation</a></li>
<li><ahref="../classes/Represents a Read Preference..html">Represents a Read Preference.</a></li>
<li><ahref="../classes/Represents a Server connection..html">Represents a Server connection.</a></li>
<li><ahref="../classes/Represents a UnorderedBulkOperation.html">Represents a UnorderedBulkOperation</a></li>
<li><ahref="../classes/Represents the Admin methods of MongoDB..html">Represents the Admin methods of MongoDB.</a></li>
<li><ahref="../classes/Represents the Grid..html">Represents the Grid.</a></li>
<li><ahref="../classes/Represents the GridStore..html">Represents the GridStore.</a></li>
* - **root** {String}, root collection to use. Defaults to **{GridStore.DEFAULT_ROOT_COLLECTION}**.
* - **content_type** {String}, mime type of the file. Defaults to **{GridStore.DEFAULT_CONTENT_TYPE}**.
* - **chunk_size** {Number}, size for the chunk. Defaults to **{Chunk.DEFAULT_CHUNK_SIZE}**.
* - **metadata** {Object}, arbitrary data the user wants to store.
*
* @param {Buffer} data buffer with Binary Data.
* @param {Object} [options] the options for the files.
* @param {Function} callback this will be called after this method is executed. The first parameter will contain an Error object if an error occured or null otherwise. The second parameter will contain a reference to this object.
// Return if we don't have a buffer object as data
if(!(Buffer.isBuffer(data))) return callback(new Error("Data object must be a buffer object"), null);
// Get filename if we are using it
var filename = options['filename'] || null;
// Get id if we are using it
var id = options['_id'] || null;
// Create gridstore
var gridStore = new GridStore(this.db, id, filename, "w", options);
gridStore.open(function(err, gridStore) {
if(err) return callback(err, null);
gridStore.write(data, function(err, result) {
if(err) return callback(err, null);
gridStore.close(function(err, result) {
if(err) return callback(err, null);
callback(null, result);
})
})
})
}
/**
* Get binary data to the grid
*
* @param {Any} id for file.
* @param {Function} callback this will be called after this method is executed. The first parameter will contain an Error object if an error occured or null otherwise. The second parameter will contain a reference to this object.
* @return {null}
* @api public
*/
Grid.prototype.get = function(id, callback) {
// Create gridstore
var gridStore = new GridStore(this.db, id, null, "r", {root:this.fsName});
gridStore.open(function(err, gridStore) {
if(err) return callback(err, null);
// Return the data
gridStore.read(function(err, data) {
return callback(err, data)
});
})
}
/**
* Delete file from grid
*
* @param {Any} id for file.
* @param {Function} callback this will be called after this method is executed. The first parameter will contain an Error object if an error occured or null otherwise. The second parameter will contain a reference to this object.