I'm not sure what the benefits of using MongoEngine in this case would be over pymongo directly. It might be cumbersome for such a large model - where as interacting with a dictionary of a known schema in my mind would be simpler.
So this all comes with a caveat and warning - it can be done in MongoEngine, I'm just not sure its your best course of action for a happy experience.
It would be a nested EmbeddedDocument eg:
class SecondAggreate(EmbeddedDocument): s0 = IntField() s1 = IntField() ... s59 = IntField() class MinuteAggregate(EmbeddedDocument): m0 = EmbeddedDocumentField(SecondAggregate) m1 = EmbeddedDocumentField(SecondAggregate) ... m59 = EmbeddedDocumentField(SecondAggregate)
Notice we have to add a
m
ors
to the keys denoting minutes and seconds because we can't have attributes that are literals. Usedb_field_name
to ensure you don't store that extra data.In the example the fields are fixed, they aren't required so you don't have to store them - but the types are defined for when you do. You could use a list but there are other considerations for lists but its simpler with a dictionary as you define the key.
Yes - see point 1.
Final caveat - if you choose to do this in MongoEngine (and as shown above you can) then don't use Doc.save()
make sure any updates are explicit as save()
may introduce race conditions if multiple threads try and update the document at the same time.