aheckmann / gridfs-stream

Easily stream files to and from MongoDB
MIT License
615 stars 120 forks source link

DeprecationWarning: GridStore is deprecated #135

Open Yaxian opened 6 years ago

Yaxian commented 6 years ago

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 commented 6 years ago

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

shashi97 commented 6 years ago

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

Yaxian commented 6 years ago

sorry, I have no idea

On Mon, Oct 8, 2018 at 6:23 PM shashi notifications@github.com wrote:

@Yaxian https://github.com/Yaxian Yaxian @venkyyPoojari https://github.com/venkyyPoojari any solution do you have as of now ?

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/aheckmann/gridfs-stream/issues/135#issuecomment-427784928, or mute the thread https://github.com/notifications/unsubscribe-auth/AJQhHYMpqiuMkqpeRmvHU6l9yy5UJocbks5uiyeWgaJpZM4WmlEp .

nerdophile commented 6 years ago

I dont have any solution as of now !!

stevenlobo commented 6 years ago

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 commented 4 years ago

then how can i read the stream.

Yaxian commented 4 years ago
  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 commented 4 years ago

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

piavgh commented 4 years ago

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

arnavzek commented 4 years ago
_id

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

arnavzek commented 4 years ago

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

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

arnavzek commented 4 years ago
_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 commented 3 years ago

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