1
我的文档存储格式为sysstat.host.statistics.timestamp[].cpu-load-all.cpu[].usr
,其中timestamp
是30个元素的数组,而cpu
是1-64元素的数组。如何干净地访问pymongo中深层嵌入的字段?
如果我抢timestamp
场,
timestampCursor = HOST_USAGE.find(
{'sysstat.host.nodename': host},
{'sysstat.host.statistics.timestamp': 1})
我怎样才能然后访问sysstat.host.statistics.timestamp[*].cpu-load-all.cpu[0].usr
,干净?我是否必须通过索引每个数组来访问每个字段,然后在每个数组字段上进行多次迭代?
这是否存储服务器端的结果?或者我可以以某种方式访问查询的结果吗? – MrDuk
当我用上面的示例填写“列表(...)”时,我得到一个返回的空列表。 – MrDuk
PyMongo的聚合返回一个游标:http://api.mongodb.com/python/current/examples/aggregation.html要将结果存储在服务器上,请使用聚合管道运算符“$ out”:https://docs.mongodb .com/v3.2/reference/operator/aggregation/out/ –