How do I set the prefix/collection that GridFS uses with the node-mongodb-native driver?

Problem

The mongo API allows for you to set what prefix the GridFS system uses. By default this is "fs", so you'll end up with the collections fs.files and fs.chunks. I'd like to have several different collections of files, so I need to be able to specify a different prefix. There isn't any information on how to do this in the documentation, nor anywhere else on the web (at least not from my searches).

Does anybody know if the node-mongodb-native driver has this capability built in? If so, how do I go about doing this?

Best,
Sami

Problem courtesy of: thisissami

Solution

You can pass the collection prefix as the second parameter when creating a new Grid in Node.JS:

var grid = new Grid(db, 'myprefix');

With GridStore, you need to add the 'root' meta property:

var gridStore = new GridStore(db, fileId, "w", {root:'myprefix'});

Easy to miss if you are looking for 'prefix' instead. There are more examples in the Tutorial.

Solution courtesy of: Stennie

Discussion

There is currently no discussion for this recipe.

This recipe can be found in it's original form on Stack Over Flow.