aheckmann / gridfs-stream

Easily stream files to and from MongoDB
MIT License
615 stars 120 forks source link

Updating file information via gridfs.files.update() #103

Open omnidan opened 7 years ago

omnidan commented 7 years ago

I am trying to update the filename and metadata via gridfs.files (as suggested by #98):

gridfs.files.update(
  { _id: req.params.id },
  { $set: { filename: req.body.filename } },
  (err, updated) => { ... }
)

However, this is not working for me on gridfs-stream 1.1.1 and mongod 3.2.11:

{ ok: 1,
     nModified: 0,
     n: 0,
     opTime: { ts: [Object], t: 1 },
     electionId: 7fffffff0000000000000001 }

Any idea what could be wrong? Did this feature break in a later version of this library/mongod?

360disrupt commented 7 years ago

I noticed that it is picky about ObjectIds. So it must be probably if you use mongoose:

ObjectId = require('mongoose').Types.ObjectId
...
_id: new ObjectId(req.params.id)

To debug, try first to find the file with your filter and then to update it.