MongoEngine/mongoengine

mongoengine not getting options from collection

dhirajpatra opened this issue · 1 comments

Using mongoengine 0.24.1 with pymongo 4.0 and as a wrapper using flask-mongoengine

One capped collection has been created with

class ZoneData(db.Document):
    zoneID = db.StringField(default="lead_test_site")
    current_zc_alert = db.IntField(default=0)
    bVoltage = db.FloatField(default=0)
    pvVoltage = db.FloatField(default=0)
    meta = {"max_documents": 1, 'max_size': 8192,
            "collection": "zone_data", 'strict': False}

When calling to fetch documents by
ZoneData.objects.get()

It is showing error that capped collection can't be created. After verified found that inside mongoengine document.py class not getting options from collections. So it is trying to create new collection, it is already there so raise error.

Andy suggestion will be helpful to find solution. Thanks

My feeling is that you have an existing collection that wasn't a capped collection and you introduce your "capped" behavior later on. Migrate your collection manually to fix this (or delete it and let MongoENgine create it), it should fix the issue

We have tests in the codebase that ensures that capped collection are created correctly (see def test_capped_collection(self): in codebase) so I doubt there is any issue there