MongoDB
 sql >> Cơ Sở Dữ Liệu >  >> NoSQL >> MongoDB

Làm cách nào để xóa giá trị tối thiểu trong mongodb cho nhóm?

Bạn có thể muốn thử:

// 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 } 
    ); 
}


  1. Redis
  2.   
  3. MongoDB
  4.   
  5. Memcached
  6.   
  7. HBase
  8.   
  9. CouchDB
  1. MongoDB - Lợi thế của việc sử dụng chuỗi 12 byte làm mã định danh duy nhất thay vì giá trị gia tăng

  2. Kéo và addtoset cùng lúc với mongo

  3. Làm cách nào để giữ giá trị null ở cuối sắp xếp trong Mongoose?

  4. MongoDB chỉ lấy các tài liệu con phù hợp từ một tài liệu có c #

  5. Sau khi nâng cấp PHP lên phiên bản 7, tại sao tôi không thể sử dụng trình điều khiển mongodb?