[英]how create mongoDB collection using data of another collection in same database
this is my one document of a collection in the mongoDB database这是我在 mongoDB 数据库中的一个集合文档
id: 1
calItems: Array
0:Object
Ts: 2016-05-01T00:00:00.000+00:00
value: 5
1:Object
Ts: 2016-05-02T00:00:00.000+00:00
value: 8
I need to create another collection with sum of these values for all documents我需要为所有文档创建另一个包含这些值的总和的集合
id:1
value: ?
You can use $out for creating new collection.您可以使用 $out 创建新集合。
db.items.aggregate([{
$project : { sumis: {$sum : "$caltems.value"}}
},
{ $out: "newCollection" }
])
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.