Reputation: 3458
I'm using a C# driver for Mongo db and I want to implement resizing of capped collections. I followed an advice from this answer, which suggests to create a new collection with a temp name, copy the documents from the old collection, remove the old collection and rename the new one. But how can I do this efficiently? The size of the current collection is 700Mb and it takes pretty much time to copy all data. It is likely that I will run this code on a machine where the server is running
Upvotes: 1
Views: 976
Reputation: 45287
But how can I do this efficiently?
You really can't. That previous answer is from Scott Hernandez who works as a Support Engineer for 10gen (the company behind MongoDB). He knows MongoDB as well as anyone on the planet, so if he his answer doesn't work, you need to come up with something completely different.
For something completely different...
Try a solution via code.
Create a new capped collection and modify your code to write to the new collection but to read from both the new and the old. It will be slightly slower (you have to check both collections before writing). But eventually all of your data will be in the new collection and you can stop reads from the old one.
Upvotes: 1
Reputation: 369
The most efficient way to resize a capped collection is still to create a new one, copy the documents over, then rename the old collection and rename the new one as spelled out in the referenced answer.
Note: Just make sure nobody is inserting/updating the old collection when you switch. If you run that code in a db.eval("....") it will lock the server while it runs.
Upvotes: 1