$out
将聚合管道中的文档,写入到一个新的集合 output
中。若是 output 已存在且有数据,则原有的数据会被清空shell
db.transactions.aggregate([ { $group: { _id: "$currency", symbols: { $push: "$symbol" } } }, { $out: "output" } ]) > db.output.find() { "_id" : "USD", "symbols" : [ "AMZN", "AAPL" ] } { "_id" : "CNY", "symbols" : [ "600519" ] }
默认状况下,每一个管道的内存操做不能超过100M,若是容许超出的话,能够设置 allowDiskUse
为 true
临时文件,默认会被写入到 dbPath下的_tmp文件夹,dbPath的默认值为 /data/db
code