Q:

Getting error while trying to save file in grid-fs using mongoose and nodejs

Trying to get GridFSBucket working for mongoose but no luck even after spending 2 days on it.  I was getting a warning related to GridStore so thought of using GridFSBucket as we are using mongoose so referred the link but the same code is not working for me. 
Following is the code I tried -
var express = require('express');
var gridfsService = express. Router();
var mongoose = require('mongoose');

const conn = mongoose.createConnection('mongodb://user:password@127.0.0.1:27017/dbname');
const gridFsBucket = new mongoose.mongo. GridFSBucket(conn.db);

The error I am getting is -
 _chunksCollection: db.collection(options.bucketName + '.chunks'),
                          ^

TypeError: Cannot read property 'collection' of undefined
    at new GridFSBucket (d:\Projects\myapp\node_modules\mongoose\node_modules\mongodb\lib\gridfs-stream\index.js:50:27)
    at Object.<anonymous> (d:\Projects\myapp\services\myapp.service.js:6:22)
    at Module._compile (module.js:652:30)
    at Object. Module._extensions..js (module.js:663:10)
    at Module.load (module.js:565:32)
    at tryModuleLoad (module.js:505:12)
    at Function. Module._load (module.js:497:3)
    at Module.require (module.js:596:17)
    at require (internal/module.js:11:18)
    at Object.<anonymous> 

I am using following versions - Nodejs-8.11.2 Mongoose- 5.0.0 mongodb - 4.0.4

A:

Had to downgrade mongoose version from latest seeing to suggestions.  It worked on mongoose version 4.13.17 (legacy).  Any other solution/suggestion is most welcome.