Created
March 19, 2015 11:03
-
-
Save riyadhalnur/64ab146dcb2098e856d4 to your computer and use it in GitHub Desktop.
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*.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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