I am trying to save a MongoEngine Document into a Dynamic Document. Sample code is as follows:
class Small(mongoengine.Document):
var_1 = mongoengine.IntField(db_field="var_1")
var_2 = mongoengine.IntField(db_field="var_2")
class Main(mongoengine.DynamicDocument):
timeseries = mongoengine.ListField(mongoengine.EmbeddedDocumentField('Small'),
db_field="timeseries")
def sample_insert():
input = [(2, 4), (2, 6), (3, None), (4, None)]
to_insert = [Small(var_1=i[0], var_2=i[1]) for i in input]
self.timeseries = to_insert
self.save()
The problem I am having occurs when one or more of the values to be saved is None. In this case the following error is generated:
mongoengine.errors.ValidationError: ValidationError (Data:55c0d57d1853bcad5c17b1f7) (var_1.Field is required)
I could set the None values to 0, but this is not a good solution as I can no longer distinguish between legitimate 0 values and non-existing values.
What I would love to do is be able to insert these None values as a 'null' entry into MongoDB.
Is this possible?