Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

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.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6062667
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T09:04:42+00:00 2026-05-23T09:04:42+00:00

Assuming I insert the following records (e.g. foo1, foo2, foo3, foo4, …. foo10) I

  • 0

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?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T09:04:43+00:00Added an answer on May 23, 2026 at 9:04 am

    Sounds like you’re looking for a capped collection:

    Capped collections are fixed sized collections…
    […]
    Once the space is fully utilized, newly added objects will replace the oldest objects in the collection.


    You can achieve this using a command similar to

    db.createCollection("collectionName",{capped:true,size:10000,max:5})
    

    where 10000 is the size in bytes and 5 is the maximum number of documents you would restrict in the collection.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Assuming a binary search tree, I would like to return an error in case
Assuming such a query exists, I would greatly appreciate the help. I'm trying to
Assuming network access is sporadic with no central server, what would be the best
Assuming I have only the class name of a generic as a string in
Assuming I have a table SomeTable with the following data: Primary Key Column1 Column2
Assuming the following markup: <fieldset> <legend>Radio Buttons</legend> <ol> <li> <input type=radio id=x> <label for=x><!--
I've cached a value using the ASP.NET Cache, with the following code: Cache.Insert(TEST_VALUE, 150,
Assuming you can't use LINQ for whatever reason, is it a better practice to
Assuming there are 5 items in the settings file ( MySetting1 to MySetting5 ),
Assuming I have an open source web server or proxy I can enhance, let's

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.