MongoDB fixed size array implementation
问题 My question is related to http://jira.mongodb.org/browse/SERVER-991. I need a nested array of a fixed size storing latest XX events related to current document. How can I implement client-side this feature? I thought of maintaining a count on array size, something like: Select count field from element Push element to embedded array If count < XX, then inc_count; Else, pop latest element; The downsides of this approach: 3 queries for each event push as mongo doesn't have transactions, the