简体   繁体   English

创建MongoDB上限集合时,指定不带size的max。

[英]Specify `max` Without `size` when Creating MongoDB Capped Collection

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 当试图创建一个MongoDB上限的集合时,其最大文档数没有限制,而没有大小限制(不确定所有文档的大小), pymongo会给出错误

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? 是否可以仅定义max参数?

Otherwise, is there any danger in putting a very large number for size ? 否则,有没有把一个非常大的数字对于任何危险size

As the docs say : 正如文档所说

The size argument is always required, even when you specify max number of documents. 即使您指定最大文档数,也始终需要size参数。 MongoDB will remove older documents if a collection reaches the maximum size limit before it reaches the maximum document count. 如果集合在达到最大文档数之前达到最大大小限制,MongoDB将删除较旧的文档。

MongoDB pre-allocates data files of the requested maximum size, so set that size parameter to something reasonable. MongoDB预分配了请求的最大大小的数据文件,因此请将size参数设置为合理的值。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM