Home > gridfs-extra > createGridFSBucket
create a gridFS bucket object to store files into mongodb
Signature:
declare function createGridFSBucket(db: mongodb.Db, options?: mongodb.GridFSBucketOptions | undefined): mongodb.GridFSBucket;
Parameter | Type | Description |
---|---|---|
db | mongodb.Db | database |
options | mongodb.GridFSBucketOptions | undefined | (Optional) options for creating gridFS bucket |
Returns:
mongodb.GridFSBucket
a mongodb GridFSBucket object
import mongodb = require(“mongodb”); import gridfs = require(‘gridfs-extra’)
// Connection URI const uri = ‘mongodb://localhost:27017/mydatabase’; // Create a new MongoClient const client = new mongodb.MongoClient(uri);
// Connect to the MongoDB server client.connect(err => { if (err) throw err;
// Get the database const db = client.db(‘mydatabase’);
// Create a new GridFSBucket const bucket = gridfs.createGridFSBucket(db)
// Close the connection client.close(); });