Closed Arcioch closed 9 years ago
Hello,
I try to use collection to read file form mongo. My code:
var gfs = Grid(conn.db); ..... gfs.collection('movies').find(where_condition).limit(1).toArray(function (err, file) { var type=''; if(node_id && file[0]) { var type=file[0]['type'];
if(type) { res.writeHead(200, {'Content-Type': type}); gfs.collection('movies').createReadStream({_id:ObjectID(file[0]['sid'])}).pipe(res); } else { res.writeHead(404, {"Content-Type": "text/html"}); res.end(); } } else { res.writeHead(404, {"Content-Type": "text/html"}); res.end(); } });
File is found but I have error: TypeError: Object # has no method 'createReadStream' But when i use it with no collection I have "record not found"
Any ideas?
The correct syntax is gfs.createReadStream and not gfs.collection('movies').createReadStream
gfs.createReadStream
gfs.collection('movies').createReadStream
If you need to read or write from a different collection please see the root option as stated in the docs.
root
Hello,
I try to use collection to read file form mongo. My code:
var gfs = Grid(conn.db); ..... gfs.collection('movies').find(where_condition).limit(1).toArray(function (err, file) { var type=''; if(node_id && file[0]) { var type=file[0]['type'];
File is found but I have error: TypeError: Object # has no method 'createReadStream'
But when i use it with no collection I have "record not found"
Any ideas?