Autoincrement Bundle for Doctrine ODM MongoDB based Symfony2 applications.
Trying to get auto increment values that are not primary keys is not a simple task using Doctrie ODM with MongoDB. This very simple bundle will help with that objective.
Autogenerated integer values are not efficient in distributed horizontal scalable databases like MongoDB so I advice not to use this values for primary keys if itended for sharded deploys.
Add following entries to config.yml
zim.autoincrement:
collection: counters
counters: ['myid']
Add as many id counters as needed on counters config value.
The bundle will add 'zim.autoincrement.generator' service to the container. To generate a new value just call service "generator" method passing the target counter name as argument.
For example inside a controller class:
$next_available_value = $this->get('zim.autoincrement.generator')->generate('myid');