Capped collections are fixed-sized collections which automatically remove the oldest documents (based on insertion order) by overwriting them once the collection is full.
Conceptually capped collections are a circular buffer rather than a queue.
This doesn't sound like a good fit for a use case of persisting order information -- there is no "hook" to re-insert documents into a capped collection when they are deleted, and if your capped collection is too small you may overwrite documents before they are processed.
I think you really want to be using a normal (non-capped) collection.
Delete old orders based on status
If you want to delete orders based on some state value, you should handle this in your application code (for example, when a order moves from "Pending" to "Processed" state do whatever cleanup is required).
Delete old/expired orders based on time
If you want to have old/expired orders automatically deleted at a specific time, a good approach would be using a normal collection with a document-level Time-To-Live (TTL) expiry, eg:
db.orders.ensureIndex( { "expireAt": 1 }, { expireAfterSeconds: 0 } )
You could then set (or extend) the expiry for each order document based on the expireAt
date. Note that this may not be a suitable option if you need to check both the expireAt
value and a status field (TTL expiry is solely based on the date index provided).