project aggregation mongodb code example

Example 1: MONGODB AGGREGATION tutorials

db.stocks.aggregate([
  { $match: { "price": 2000 } }
])

Example 2: mongodb project all fields

db.collection.aggregate([
    { "$addFields": { "custom_field": "$obj.obj_field1" } }
])

Example 3: MONGODB AGGREGATION tutorials

db.stocks.insertMany([
   { name: "Infosys", qty: 100, price: 800 },
   { name: "TCS", qty: 100, price: 2000 },
   { name: "Wipro", qty: 2500, price: 300 }
])

Example 4: MONGODB AGGREGATION tutorials

db.stocks.find().pretty()

Tags:

Go Example