Is it possible to create a capped sub-collection. I'm trying to do something like:
user = {
name: String,
latest_messages: [String]
}
Where the latest_messages are capped to 10.
If not, what do you suggest as an alternative?
Update 1:
It appears as though keeping the array capped manually is the only solution. Here's a way to do this:
joe = {name: 'Joe', latest_messages: ['', '', '', '', '', '', '', '', '', '']}
db.users.save(joe)
db.users.update({name: 'Joe'}, {$push: {'latest_messages': 'hello'}})
db.users.update({name: 'Joe'}, {$pop: {'latest_messages': -1}})
db.users.update({name: 'Joe'}, {$push: {'latest_messages': 'world'}})
db.users.update({name: 'Joe'}, {$pop: {'latest_messages': -1}})
Any suggestions on making this more efficient?
Update 2:
There's an open Jira ticket, "SERVER-1050" that requests to add the ability to do the two (push & pop) as one atomic operation.