Some time ago read a coder write with Gridfs-stream to store files, feel good on their own with the Gridfs-stream module to write a file storage service, but found that the stored files are always deleted, I call the GFS's remove API, Delete the _id that the condition is used for.
Gfs.remove ({_id: ' xxxxxx '}, callback);
Resistance to look at the source code, found that the direct cause of the problem is because I do not use MongoDb ObjectId as a result of _id. I'm using a string of my own definition.
Looking back at the Gridfs-stream document, I finally found in a note in the sample code
_id: ' 50e03d29edfdc00d34000001 ',//a MongoDb ObjectId
Immediately 10,000 grass mud horse ....
If you must customize the string as a file storage _id, there is a way, but to modify the source of the MongoDB module, in the MongoDB module \lib\gridfs\grid_store.js file has a unlinkstatic method, There's a sentence inside
New Gridstore (db, Names, "W", Options)
Switch
New Gridstore (db, names, ', ' w ', options)
Can. Specific reasons to see the source of their own it.
Use Gridfs-stream to store files encountered by a pit.