Optimization and limitation of mongodb aggregation pipeline

Time:2020-6-24

$out
Write documents from the aggregation pipeline to a new collectionoutputMedium. If the output already exists and has data, the original data will be cleared

db.transactions.aggregate([
    {
        $group: {
            _id: "$currency",
            symbols: {
                $push: "$symbol"
            }
        }
    },
    {
        $out: "output"
    }
])
> db.output.find()
{ "_id" : "USD", "symbols" : [ "AMZN", "AAPL" ] }
{ "_id" : "CNY", "symbols" : [ "600519" ] }

Option settings for aggregation operations

  • allowDiskUse

By default, the memory operation of each pipeline cannot exceed 100m. If it is allowed to exceed 100m, it can be setallowDiskUseTrue
Temporary file, written to dbpath by default_ Tmp folder, default value of dbpath is/data/db