要获取集合“ col1”上字段“ field1”的不同值的出现,并将其写入单独的集合“ distinctCount”。如果集合很大,还可以使用磁盘空间。
db.col1.aggregate( [{$group: { _id: "$field1", count: { $sum : 1 } }}, { $group: { _id: "$_id", count: { $sum : "$count" } }},{ $out: "distinctCount" }], {allowDiskUse:true})
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)