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
I’m using a C# driver for Mongo db and I want to implement resizing
Share
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.