Heterogeneous Lists in Python MongoEngine
The ListField
does not enforce a datatype unless you ask it to. However if you do then it has to be a single datatype at the moment. For example
This works:
import mongoengine as mdbclass Stuff(mdb.Document): things = mdb.ListField()s = Stuff(things=['1',2,[4,5]])s.save()
this throws TypeError
as it is enforcing a datatype:
import mongoengine as mdbclass Stuff(mdb.Document): things = mdb.ListField(mdb.IntField())s = Stuff(things=['1',2,[4,5]])s.save()
this throws AttributeError
as it is expecting a Field as the first argument:
import mongoengine as mdbclass Stuff(mdb.Document): things = mdb.ListField([mdb.IntField(),mdb.StringField(),mdb.ListField()])s = Stuff(things=['1',2,[4,5]])s.save()
I can see the final example being a useful so you might want to file an issue on the project repo.