Specify `max` Without `size` when Creating MongoDB Capped Collection

538 Views Asked by At

When trying to create a MongoDB capped collection with only a limit for the max number of documents and not a size limit (not sure how large will all the documents be), pymongo is giving the error

pymongo.errors.OperationFailure: specify size:<n> when capped is true

after running

db.create_collection('helloworld', capped=True, max=86400)

Is it possible to just define the max parameter?

Otherwise, is there any danger in putting a very large number for size?

1

There are 1 best solutions below

0
A. Jesse Jiryu Davis On

As the docs say:

The size argument is always required, even when you specify max number of documents. MongoDB will remove older documents if a collection reaches the maximum size limit before it reaches the maximum document count.

MongoDB pre-allocates data files of the requested maximum size, so set that size parameter to something reasonable.