Reputation: 7859
I'm copying a Mongo DB collection from a database to another, using Morphia in that way:
List<User> users = datastoreSource.find(User.class).asList();
datastoreDest.save(users);
This code works, however it takes hours to perform. I have a collection with 3 million documents in it and I would expect to copy it in few minutes. Can someone help me to improve that code?
Upvotes: 0
Views: 547
Reputation: 10859
I'm amazed this is working at all with 3 million documents. First you are loading them all into memory and then you are writing them back.
I would try reading a batch of data (say 100) with .order("_id").limit(100).skip(i*100)
and bulk write it back.
And it would be interesting:
Upvotes: 1