Does anyone know how to create a model with an embedded document with mongo alchemy? I've search in the documentation, but there isn't any example about doing that.
Asked
Active
Viewed 1,175 times
2 Answers
3
have a look at:
https://github.com/jeffjenkins/MongoAlchemy/blob/master/examples/examples.py
Theres a sample there, but for completeness, yes MongoAlchemy can use embedded documents like this:
class Address(Document):
street_address = StringField()
city = StringField()
state_province = StringField()
country = StringField()
class User(Document):
name = StringField()
email = StringField()
address = DocumentField(Address)
user = User()
user.name = "tony"
user.address = Address()
user.address.city = "London"

Tony Million
- 4,296
- 24
- 24
1
I didn't see anything in mongoAlachemy
for embedded documents:
see here:
- Schema — Document-Object Mapper and Schema Definitions — MongoAlchemy v0.12 documentation -> http://www.mongoalchemy.org/api/schema/index.html
I suggest you use mongoengine
for better result:
- MongoEngine/flask-mongoengine · GitHub -> https://github.com/MongoEngine/flask-mongoengine
- https://flask-mongoengine.readthedocs.org/en/latest/#supported-fields

Mohammad Efazati
- 4,812
- 2
- 35
- 50