Noel
Noel

Reputation: 5369

MongoDB Capped Collection max size 2G

I have worked out the size of my documents for a 6 month period and it comes to just over 2 Gigs. I want to keep onto all documents until the 6 month period is reached(does not need to be exact), so if i do this it works:

db.create_collection('mycollection', capped=True, size=2000000000)

My questions are:

Will mongo allocate this space immediately for the collection?

Is this bad practice to create a capped collection this size?

Most examples I see are set quiet small for the size.

I dont want to use the "Expire Data from Collections by Setting TTL"

Upvotes: 2

Views: 524

Answers (1)

ThrowsException
ThrowsException

Reputation: 2636

Yes MongoDB will preallocate that space for the collection. Id suggest some kind of archiving methodology if your goal is to only be working with data thats about 6 months old and just have a process that moves old data into another collection. The capped collections would be a bad practice if you are updating the documents and using this as a write heavy collection. If your collection is just read heavy then it's fine but if you are updating these documents theres the potential that an update will fail if a document grows larger than its initial size. In a capped collection documents can not grow in size.

Another approach to this kind of setup that only wants to deal with most recent data would be to use tag aware sharding so that data that fits within a certain range is at the ready on fast hardware that gets accessed first, and older data gets pushed off to the slower, more commodity, hardware.

Upvotes: 2

Related Questions