I've been confused with this error. I'm creating a Vehicle database with mongoengine that goes like this.
class Vehicles(Document):
make: StringField()
model: StringField()
license: StringField()
year: IntField()
mileage: IntField()
deleted: BooleanField()
for j in range(2):
vehicle = Vehicles(
make="Honda",
model="Civic",
license="H54 " + str(i) + str(j),
year=2015,
mileage= 500 + (i * 500),
deleted=False
).save()
While I try running the code, I've been getting:
mongoengine.errors.FieldDoesNotExist: The fields "{'license', 'year', 'model', 'mileage', 'make', 'deleted'}" do not exist on the document "Vehicles"
I don't understand why it's giving me this error. I know a solution is to change Document into DynamicDocument, but I don't really see why. Can someone please explain to me this error???
You are writing your class as if it was a dataclass but Mongoengine has no support for type hinting so it is not intepreting that correctly. MongoEngine is in fact currently not seeing any of your field definitions.
Turn your ":" into "=" and it should be fine
class Vehicles(Document):
make = StringField() # instead of 'make : StringField()'
...
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With