Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DeprecationWarning: GridStore is deprecated #135

Open
Yaxian opened this issue Sep 13, 2018 · 13 comments
Open

DeprecationWarning: GridStore is deprecated #135

Yaxian opened this issue Sep 13, 2018 · 13 comments

Comments

@Yaxian
Copy link

Yaxian commented Sep 13, 2018

mongodb version is 3.1.1

(node:65150) DeprecationWarning: GridStore is deprecated, and will be removed in a future version. Please use GridFSBucket instead

@nerdophile
Copy link

(node:3209) DeprecationWarning: GridStore is deprecated, and will be removed in a future version. Please use GridFSBucket instead

@shashi97
Copy link

shashi97 commented Oct 8, 2018

@Yaxian Yaxian @venkyyPoojari any solution do you have as of now ?

@Yaxian
Copy link
Author

Yaxian commented Oct 8, 2018 via email

@nerdophile
Copy link

I dont have any solution as of now !!

@stevenlobo
Copy link

The mongoose docs at https://mongoosejs.com/docs/deprecations.html#-gridstore- indicates the reason for the depreciation warning and path forward:

That is because gridfs-stream relies on a deprecated MongoDB driver class. 
You should instead use the MongoDB driver's own streaming API 

// Replace this:
const conn = mongoose.createConnection('mongodb://localhost:27017/gfstest');
const gfs = require('gridfs-store')(conn.db);
const writeStream = gfs.createWriteStream({ filename: 'test.dat' });

// With this:
const conn = mongoose.createConnection('mongodb://localhost:27017/gfstest');
const gridFSBucket = new mongoose.mongo.GridFSBucket(conn.db);
const writeStream = gridFSBucket.openUploadStream('test.dat');

There is also a link on that site that provides usage examples of GridFSBucket.

@binoysarker
Copy link

then how can i read the stream.

@Yaxian
Copy link
Author

Yaxian commented Dec 19, 2019

  import {GridFSBucket, MongoClient, ObjectId} from 'mongodb';
  import { Readable } from 'stream';

  let connection = MongoClient.connect(url, { 
       useNewUrlParser: true,
       useUnifiedTopology: true
   } );
  let db = connection.db(dbName);
  let gridfsBucket = new GridFSBucket(db, {bucketName: bucketName});
  let downloadStream = gridfsBucket.openDownloadStream(new ObjectId(_id));

  let buffer = [];
  downloadStream.on('data', (chunk) => {
       buffer.push(chunk);
  });
  downloadStream.on('end', () => {
       let readable = new Readable();
       readable._read = () => {};
       readable.push(Buffer.concat(buffer));
       readable.push(null);
  });

@piavgh
Copy link

piavgh commented Apr 27, 2020

How about the function gfs.files.find(...) ?

@piavgh
Copy link

piavgh commented Apr 27, 2020

Also gfs.files.update(...) ?

@arnavzek
Copy link

_id

what exactly is _id, if it is not the file name how can I find id from filename?

@arnavzek
Copy link

How about the function gfs.files.find(...) ?

you can instead query bucketName.files with mongoose it is not too bad

@arnavzek
Copy link

_id

what exactly is _id, if it is not the file name how can I find id from filename?

do I need to use mongoose find query on top of that?

@Nikitas-io
Copy link

How about the function gfs.files.find(...) ?

Here's how I did it:

connection.db.collection("media.files").find().toArray((err, files) => {
      // Return the files that exist.
      return res.json(files);
})

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

8 participants