MongoDB
 sql >> Datenbank >  >> NoSQL >> MongoDB

Wie entferne ich den Mindestwert in Mongodb für die Gruppe?

Vielleicht möchten Sie Folgendes versuchen:

// this returns an array of documents which has the store_id and the minimum price for that store
myresult = db.products.aggregate( [ 
                            { $group: 
                                 { _id: "$store_id", 
                                   price: { $min: "$price" } 
                                 } 
                            } 
                            ] ).result

// loop through the results to remove the documents matching the the store id and price

for (i in myresult) { 
    db.products.remove( 
         { store_id: myresult[i]._id, price: myresult[i].price } 
    ); 
}