Articles → MONGODB → $Out Aggregation Operator In Mongodb$Out Aggregation Operator In MongodbIn this article, we will discuss the $out aggregation operator in MongoDB.Purpose The $out stage is used in aggregation pipelines to write the results of the aggregation query to a collection.Example Consider the following collection: -To write the result of an aggregation, we will write the following query: -db.orders.aggregate([ { $group: { _id: "$customerId", firstOrderId: { $first: "$_id" } } }, { $out: "total_costs" } ])Output Posted By - Karan Gupta Posted On - Thursday, June 13, 2024 Query/Feedback Your Email Id** Subject* Query/Feedback Characters remaining 250**
db.orders.aggregate([ { $group: { _id: "$customerId", firstOrderId: { $first: "$_id" } } }, { $out: "total_costs" } ])
Query/Feedback