Assuming I insert the following records (e.g. foo1, foo2, foo3, foo4, …. foo10)
I would like the collection to retain only 5 records at any point in time (e.g. it could be foo1, … foo5 OR foo2, … foo6 or foo6, … foo10)
How should I achieve this?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Sounds like you’re looking for a capped collection:
You can achieve this using a command similar to
where 10000 is the size in bytes and 5 is the maximum number of documents you would restrict in the collection.