如题,mongodb数据库,使用的mongoengine建立的ORM模型,现有一个实体内有一个List类型的字段,如:
class Service(Document): ... xx = ListField(StringFiled(...)) ...
现在我想将每个Service文档记录下的xx字段的列表,汇总到一个list,怎么写比较合理呢? 有mongoengine语法更法,没有告诉我pymongo也行,提代个思路,谢谢!
ringa_lee
Aggregation Framework (2.2 and later) can easily solve this problem. http://docs.mongodb.org/manual/core/aggregation-introduction/
We can meet your needs at $group操作中,$push或者$addToSet. Drivers such as pymongo also support Aggregation Framework.
$group
$push
$addToSet
Aggregation Framework (2.2 and later) can easily solve this problem. http://docs.mongodb.org/manual/core/aggregation-introduction/
We can meet your needs at
$group
操作中,$push
或者$addToSet
. Drivers such as pymongo also support Aggregation Framework.