gridfs-stream
gridfs-stream copied to clipboard
DeprecationWarning: GridStore is deprecated
mongodb
version is 3.1.1
(node:65150) DeprecationWarning: GridStore is deprecated, and will be removed in a future version. Please use GridFSBucket instead
(node:3209) DeprecationWarning: GridStore is deprecated, and will be removed in a future version. Please use GridFSBucket instead
@Yaxian Yaxian @venkyyPoojari any solution do you have as of now ?
sorry, I have no idea
On Mon, Oct 8, 2018 at 6:23 PM shashi [email protected] 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 .
I dont have any solution as of now !!
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.
then how can i read the stream.
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);
});
How about the function gfs.files.find(...)
?
Also gfs.files.update(...)
?
_id
what exactly is _id, if it is not the file name how can I find id from filename?
How about the function
gfs.files.find(...)
?
you can instead query bucketName.files with mongoose it is not too bad
_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?
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);
})