Limit Multiple MongoDB Array Size

为君一笑 提交于 2019-12-02 08:30:59

If I understand correctly Capped Collections are what you want. http://www.mongodb.org/display/DOCS/Capped+Collections

As it turns out, this was a longstanding issue in MongoDB that was since added in MongoDB 2.4 release using the $slice operator.

db.students.update(
                { _id: 1 },
                { $push: { scores: { $each : [
                                               { attempt: 3, score: 7 },
                                               { attempt: 4, score: 4 }
                                             ],
                                     $sort: { score: 1 },
                                     $slice: -3
                                   }
                          }
                }
              )

http://docs.mongodb.org/manual/tutorial/limit-number-of-elements-in-updated-array/

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!