How do I clone a collection with MongoDB and ignore duplicate keys?
$ mongo items
MongoDB shell version: 2.4.6
connecting to: items
> db.cloneCollection('localhost:27018', 'things')
{
"errmsg" : "exception: E11000 duplicate key error index: items.things.$_id_ dup key: { : ObjectId('52558bebdedc25038ed26d58') }",
"code" : 11000,
"ok" : 0
}
Better yet, is there a safer way of merging a remote collection with a local one? If db.cloneCollection
is interrupted, there doesn't seem to be a way to "resume" it without wiping out all of the duplicate items and restarting it from the beginning.