Get Even More Visitors To Your Blog, Upgrade To A Business Listing >>

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

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

View additional discussion.



This post first appeared on Node.js Recipes, please read the originial post: here

Share the post

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

×

Subscribe to Node.js Recipes

Get updates delivered right to your inbox!

Thank you for your subscription

×