Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
We have an app running on the MEAN stack and are using MongooseJS as our ORM. Now, we have 2 collections *event* and *eventV2*. We are looking to drop the *event* collection and rename the *eventV2* collection to just *event*.
var mongoose = require('mongoose');
var async = require('async');
var db = 'mongodb://localhost/myawesomeapp';
mongoose.connect(db, function (err) {
if (err) { throw err; }
async.series([_dropCollection, _renameCollection], function (err, result) {
if (err) { throw err; }
console.info('Completed successfully! Result: ' + result);
process.exit();
});
});
function _dropCollection(callback) {
mongoose.connection.db.dropCollection('event', function (err, result) {
if (err) { callback(err); }
callback(null, result);
});
}
function _renameCollection(callback) {
mongoose.connection.db.renameCollection('eventV2', 'event', function (err, result) {
if (err) { callback(err); }
callback(null, result);
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.