Company
Date Published
Author
MongoDB
Word count
503
Language
English
Hacker News points
None

Summary

MongoDB version 2.4 introduced a capped array feature, allowing developers to create fixed-size lists with sorting capabilities. This feature is particularly useful for applications that need to track limited information, such as the last viewed products in an ecommerce application or the newest messages in a messaging system. With capped arrays, developers can push values into an array and then slice it to a specific size, maintaining the natural order of the elements. The $slice operator allows specifying the start or end of the array to be sliced from, and sorting can also be applied using the $sort operator. This feature is available in MongoDB 2.4 but has been extended with plans for full $sort and $slice semantics in $push and making the $slice operation optional in a future version.