0

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

thisissami
  • 15,445
  • 16
  • 47
  • 74

1 Answers1

4

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.

Stennie
  • 63,885
  • 14
  • 149
  • 175
  • ah so you'd have to use Grid as opposed to GridStore? no way to set the collection with GridStore? Thanks for your response. – thisissami Jul 12 '12 at 23:48
  • 1
    @thisissami added GridStore example as well. It's included in the tutorial example code but seems to be missing an explanation there. See [API docs for GridStore](http://mongodb.github.com/node-mongodb-native/api-generated/gridstore.html) for `root` and other optional properties. – Stennie Jul 13 '12 at 00:23
  • awesome thanks. i've been using the docs in the github page itself. this mongodb subdomain is new! thanks for the help. – thisissami Jul 13 '12 at 02:03
  • @thisissami: fyi, the [mongodb.github.com](http://mongodb.github.com/node-mongodb-native/) docs are the same as in the [node-mongodb-native github](https://github.com/mongodb/node-mongodb-native/tree/master/docs) .. but run through [Sphinx](http://sphinx.pocoo.org/) which adds navigation, search, and better presentation. – Stennie Jul 13 '12 at 02:33
  • oh i never looked under "articles" - just the regular gridfs – thisissami Jul 13 '12 at 02:35