renameCollection with Meteor

How do I use renameCollection with Meteor? I would like to do this inside Meteor because I need do migrations for development and production environment.

Check this out: and show your support there, perhaps.

For a given Mongo.Collection instance, you can call .rawCollection() and then call .renameCollection() after it (in addition to any other native MongoDB API). It only works on the server.

var myCollection = new Mongo.Collection('myCollection');
myCollection.rawCollection().renameCollection(/* ... */);

PS - I don’t remember if this has changed yet, but if you’re using an older version of Meteor you might need to use .rename() (MongoDB 1.4) instead of .renameCollection() (MongoDB 2.x).

1 Like

myCollection.rawCollection().renameCollection(/* ... */); gives me
TypeError: Object [object Object] has no method 'renameCollection'

myCollection.rawCollection().rename(/* ... */); gives me
TypeError: Cannot read property 'dropTarget' of undefined

You need to use this API:

Decided to manually rename the collection… Can’t believe that there’s no straight forward solution to this.