Open curtw opened 9 years ago
Code to reproduce....
var queryOptions = {
//*** NOTE: choose one, comment other. Works with filename. Fails with _id.
//filename: 'my_file.txt'
_id: 'ABC123'
}
var createOptions = {
filename: 'my_file.txt',
_id: 'ABC123'
};
var mongo = require('mongodb'),
Grid = require('gridfs-stream'),
stream = require('stream');
var db = new mongo.Db('issue85', new mongo.Server("127.0.0.1", 27017));
db.open(function (err) {
if (err) {
console.log('An error occurred!', err);
throw err;
}
//drop database before test
db.dropDatabase();
var gfs = Grid(db, mongo);
var writestream = gfs.createWriteStream(createOptions);
writestream.on('close',function(){
gfs.exist(queryOptions,function(err, found){
if (found) {
console.log('Found file. It says... ');
var readstream = gfs.createReadStream(queryOptions);
readstream.pipe(process.stdout);
}
else {
console.log('Sorry, file not found.');
}
});
});
var bufferStream = new stream.PassThrough();
bufferStream.end(new Buffer('Hello World.'));
bufferStream.pipe(writestream);
})
Same here, I tried with a valid ObjectId
value as _id and works, but when try using md5 as _id, exists is always false
Using Grid.exist with options like {_id : "ABC123"} will always return found=false even if that _id exists in the fs.files colleciton. In contrast, if options is like {filename: "cat1.png"} then it works fine. This is with version gridfs-stream version 1.1.1.