Remove expired keys from view


#1

I want to build view next way, for example:

users:{
“10”:{
uid:"10"
type:‘user’,
name:‘Username’,
items:{
343:{‘level’:4, ‘price’:124, ‘expire’:140232233},
345:{‘level’:5, ‘price’:100, ‘expire’:140236630},
}
},
“11”:{
uid:"10"
type:‘user’,
name:‘Username’,
items:{
340:{‘level’:4, ‘price’:124, ‘expire’:140232233},
341:{‘level’:5, ‘price’:100, ‘expire’:140236630},
}
},

}

Code of view something like this:

function (doc, meta) { if(type == 'user' && doc.items) { for(var id in doc.items){ var item = doc.items[id]; emit([id, item.level, item.expire], doc.uid); } } }

What will be with keys if user will change the document? New items will be emitted to view, but what will be with old items, which have already expired? Will it be deleted?