0

I'm reading GridFS's docs and I'm not sure I'm understanding it. It says right here https://github.com/mongodb/node-mongodb-native/blob/1.4/examples/gridfs.js#L75 that I should delete a file using it's name. But that's just both insane and stupid. Two files with the same name can coexist perfectly inside the same collection by having different _id. There should be a way to delete files by their _id instead of by their name, but I can't find it.

My question is: has anybody delete files from GridFS using ids instead of names? How?

alexandernst
  • 14,352
  • 22
  • 97
  • 197

3 Answers3

1

I've never used Node.JS but if you want to remove file using _id you should use delete and as far as I can tell it is implemented in Node.JS driver: https://github.com/mongodb/node-mongodb-native/blob/1.4/lib/mongodb/gridfs/grid.js#L95

zero323
  • 322,348
  • 103
  • 959
  • 935
  • I tried that but it says there is no method ```delete```, and I can't see it on the docs page: http://mongodb.github.io/node-mongodb-native/api-generated/gridstore.html – alexandernst Oct 03 '13 at 14:38
  • Maybe this http://blog.nodeknockout.com/post/35215400231/a-primer-for-gridfs-using-the-mongo-db-driver will be helpful. – zero323 Oct 03 '13 at 18:36
0

I found what I was looking for: http://mongodb.github.io/node-mongodb-native/api-generated/grid.html#delete

Wasn't looking in the right place.

@zero323 you were right :)

alexandernst
  • 14,352
  • 22
  • 97
  • 197
0

The GridFSBucket API on the mongo nodejs driver defines a delete method which accepts an ID parameter.

Riky_Tree
  • 561
  • 6
  • 7