2

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.

danielrvt
  • 10,177
  • 20
  • 80
  • 121

2 Answers2

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:

I suggest you use mongoengine for better result:

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