mongoose-gridfs-extra

Home > mongoose-gridfs-extra > createGridFSBucket

createGridFSBucket() function

create a gridFS bucket object to store files into mongodb

Signature:

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

Parameters

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

Returns:

mongo.GridFSBucket

a mongodb GridFSBucket object

Example

import {mongoose} = require("mongodb");
import gridfs = require('mongoose-gridfs-extra')

const uri = 'mongodb://localhost:27017/test';
const connection = await mongoose.createConnection(uri).asPromise()
const db = connection.db

// Create a new GridFSBucket
const bucket = gridfs.createGridFSBucket(db)

// Close the connection
connection.close();