gridfs-extra

Home > gridfs-extra > createGridFSBucket

createGridFSBucket() function

create a gridFS bucket object to store files into mongodb

Signature:

declare function createGridFSBucket(db: mongodb.Db, options?: mongodb.GridFSBucketOptions | undefined): mongodb.GridFSBucket;

Parameters

Parameter Type Description
db mongodb.Db database
options mongodb.GridFSBucketOptions | undefined (Optional) options for creating gridFS bucket

Returns:

mongodb.GridFSBucket

a mongodb GridFSBucket object

Example

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(); });