Closed char1st closed 9 years ago
... I found the reson
The gfs.files.find must be called at on gfs.createWriteStream() close.
like that
fs.createReadStream(filename).pipe(gfs.createWriteStream({filename:filename}).on('close',function(){ gfs.files.find({filename:filename}).toArray(function(err,docs){console.log(docs)}); }));
var MongoClient = mongo.MongoClient; MongoClient.connect("mongodb://127.0.0.1:27017/test",function(err,db){ var gfs=Grid(db,mongo); var filename='tmp.json'; fs.createReadStream(filename).pipe(gfs.createWriteStream({filename:filename})); gfs.files.find({filename:filename}).toArray(function(err,docs){console.log(docs)}); });
The docs is empty sometimes . Why ? Do i used the gridfs-stream in a wrong way ?