mongoose icon indicating copy to clipboard operation
mongoose copied to clipboard

ReferenceError: files is not defined at gfs.files.find.toArray

Open aalparslan opened this issue 7 years ago • 6 comments

Do you want to request a feature or report a bug?

What is the current behavior?

If the current behavior is a bug, please provide the steps to reproduce.

What is the expected behavior?

What are the versions of Node.js, Mongoose and MongoDB you are using? Note that "latest" is not a version.

aalparslan avatar Jun 09 '19 07:06 aalparslan

I am want to use gridfs-stream to retrive images from mongoose database but I get this error.

I set gfs above like that and below I called gfs.files.find() method to get images.I have been stuck on gfs.files. Can anyone help?

aalparslan avatar Jun 09 '19 07:06 aalparslan

Can you please provide some code samples?

vkarpov15 avatar Jun 09 '19 21:06 vkarpov15

I also have this problem... files is not defined. Could be the database and the setup of my project.

Danielhoifodt avatar Apr 03 '20 12:04 Danielhoifodt

@DanielBaulig please open a new issue following the issue template.

AbdelrahmanHafez avatar Apr 03 '20 12:04 AbdelrahmanHafez

  gfs.files.find().toArray((err, files) => {
    if (!files || files.length === 0) {
      res.render('dashboard', { files: false });
    } else {
      files.map(file => {
        if (
          file.contentType === 'image/jpeg' ||
          file.contentType === 'image/png'
        ) {
          file.isImage = true;
        } else {
          file.isImage = false;
        }
      });
      res.render('dashboard', { files: files});
    }
    
  });
  res.render('dashboard', { username : req.user.username });
});```
I get "files" not defined.... i have files in my database, but the function i eighter depricated or i have an error somewhere else...

Danielhoifodt avatar Apr 03 '20 21:04 Danielhoifodt

@Danielhoifodt Why are you calling res.render() twice? Looks like you're calling render() once immediately and then once after you load the files?

vkarpov15 avatar Apr 10 '20 20:04 vkarpov15