class UserThings(DynamicDocument):
username = StringField()
things = DictField()
dcrosta_things = UserThings(username='dcrosta')
dcrosta_things.things['foo'] = 'bar'
dcrosta_things.things['bad'] = 'quack'
dcrosta_things.save()
MongoDB文档中的结果如:
{ _id: ObjectId(...),
_types: ["UserThings"],
_cls: "UserThings",
username: "dcrosta",
things: {
foo: "bar",
baz: "quack"
}
}
我使用的是mongoengine,我无法查询dict字段的密钥。
例如,我有一个事项列表thing_list = ['foo', 'faa', 'baz', 'xyz']
我希望过滤包含任何这些内容的所有UserThings
...
类似...... UserThings.objeect.filter(things__in=thing_list)