I have an express application that works when I run it locally. The problem is loading a file that is saved in mongoDB using GridFS. When I run it locally (I just do. / Bin / www and switch to localhost: 3000), I can upload the file. But when I run it remotely, I load the html file.
This is the route that processes the response:
router.get('/getfile',function(req,res) {
if (req.isAuthenticated())
{
var gfs = Grid(mongoose.connection, mongoose.mongo);
var id = req.query.id;
gfs.exist({_id: id}, function (err, found) {
if (err) return handleError(err);
if (!found)
res.send('Error on the database looking for the file.')
});
var readStream = gfs.createReadStream({
_id: id
}).pipe(res);
}
else
res.redirect('/login');
});
which is called by this line in the jade file:
td
On the server, I do:
/logApp$ export NODE_ENV=production
/logApp$ ./bin/www
works monoDB deamon. In fact, I can query the database. And I do not write any files! I want to read it.
EDIT: I found the error message:
MongoError: file with id
source
share