I'm using nodejs mongodb mongoose and gridfs. when I try to get a file by it's filname everthing is working great by if i want to get it by id i get Error: The file you wish to read does not exist. I the following code the console.log("res.pic_id : " + res.pic_id) i get the correct ObjectId. Here's the code :
var GridFS = require('GridFS').GridFS;
var myFS = new GridFS('db');
var fs = require('fs')
var Profile = db.model('Profile');
Profile.findOne({'_id' : clientID},['_id', 'username','pic_id','pic_filename'],function(err, res){
if (err) {
console.log("ERROR serching user info: " + err);
callback(JSON.stringify(JSONRes(false, err)));
}
else {
if (res) {
console.log("res.pic_id : " + res.pic_id);
myFS.get(res.pic_id,function(err,data){
if (err)
console.log("ERROR "+err)
else {
callback(data);
}})
};
}
else {
callback(JSON.stringify(JSONRes(false, err)));
}
}
})
Thank you!