MongoDb capped sub-collection -


is possible create capped sub-collection. i'm trying like:

user = {   name: string,   latest_messages: [string] } 

where latest_messages capped 10.

if not, suggest alternative?

update 1:

it appears though keeping array capped manually solution. here's way 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 more efficient?

update 2:

there's open jira ticket, "server-1050" requests add ability 2 (push & pop) 1 atomic operation.

you can specify overall number of documents of capped collection. there no way limit size of array unless through checks in app.


Comments

Popular posts from this blog

c# - SharpSVN - How to get the previous revision? -

c++ - Is it possible to compile a VST on linux? -

url - Querystring manipulation of email Address in PHP -