有人能帮助我吗?我试图简单地检索“地址”字段中的内容。除了空括号“[]”之外,我无法打印任何内容
这是一个示例记录:
{
"_id": { "$oid" : "51376F833EF9EB361F354ED0" },
"addresses": [
{
"city": "CAMBRIDGE",
"suffix": "",
"street_name": "FRANKLIN ST",
"prefix": "",
"zipcode": "49503",
"state": "MA",
"street_num": "127"
}
],
"created_at":{ "$date": 1361160419000.000000 }
}
这是我的课程代码:
class Buildings(db.Document):
_id = db.ObjectIdField(required=True)
addresses = db.ListField(db.EmbeddedDocumentField('Address'))
created_at = db.DateTimeField(default=datetime.datetime.now, required=False)
meta = {
'allow_inheritance': False,
'indexes': ['_id'],
'ordering': ['-created_at']
}
class Address(db.EmbeddedDocument):
city = db.StringField(required=False)
suffix = db.StringField(required=False)
street_name = db.StringField(required=False)
zipcode = db.StringField(required=False)
prefix = db.StringField(required=False)
state = db.StringField(required=False)
is_contracted = db.IntField(required=False)
street_num = db.StringField(required=False)
还有一个循环应该打印嵌入的 Document 但只为每个对象返回一个 [] 。
for building in Buildings.objects:
print building.addresses
知道为什么这不起作用吗?