21. Capped Collections¶
Capped collections are fixed sized collections that have a very high performance auto-LRU age-out feature (age out is based on insertion order).
In addition, capped collections automatically, with high performance, maintain insertion order for the objects in the collection; this is very powerful for certain use cases such as logging.
21.1. Mapping¶
You can configure the collection in the collection attribute of the @Document annotation:
<?php
/**
* @Document(collection={
* "name"="collname",
* "capped"="true",
* "size"="100000",
* "max"="1000"
* })
*/
class Category
{
/** @Id */
public $id;
/** @String */
public $name;
}
21.2. Creating¶
Remember that you must manually create the collections. If you let MongoDB create the collection lazily the first time it is selected, it will not be created with the capped configuration. You can create the collection for a document with your DocumentManager instance:
<?php
$dm->createDocumentCollection('Category');
You can drop the collection too if it already exists:
<?php
$dm->dropDocumentCollection('Category');
