Skip to content

Instantly share code, notes, and snippets.

@azat
Created May 21, 2012 12:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save azat/2762148 to your computer and use it in GitHub Desktop.
Save azat/2762148 to your computer and use it in GitHub Desktop.
mongodb manually unshard
// set
var collection = ;
var db = ;
var fromHost = ;
// unshard
db = db.getMongo().getDB(db);
var collection = db.getCollection(collection);
var m = new Mongo(fromHost);
var remoteCollection = m.getDB(db).getCollection(collection);
var i = 0;
collection.find().forEach(function(row) {
remoteCollection.insert(row);
collection.remove({_id: row._id});
if ((++i % 50000) == 0) {
print("Updated: " + i);
}
});
print("Updated: " + i);
@ti24horas
Copy link

Using this method, mongodb will not balance while you're inserting in another collection?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment