I’m using Doctrine MongoDB ODM in a Symfony2 application.
How can I set default commit options (such as safe: 3 and fsync: true)?
Ideally I’d be able to do this in my YAML config files, but the docs seem to indicate this isn’t possible.
If I can get the Configuration object I should be able to set defaultCommitOptions (like fsync) there, but I’m not sure how/when/where to do that.
As of PR #114, you can use the top-level configuration option
default_commit_optionsfor this. By default, the bundle will use the same value as ODM, which is{safe: true}. Here’s a quick example of the supported options:Take a look at the Configuration class and unit tests for the DI extension for more information.
For older versions of DoctrineMongoDBBundle, the Configuration class is registered in the service container, which means you can implement it on your own. Two options for doing so would be to create a compiler pass in your own bundle and add the method call on the service definition or, if that is too complex, access the service instance in your runtime code and call
setDefaultCommitOptions()directly.The code of interest is in DoctrineMongoDBExtension and the
loadDocumentManager()method. From there, you can see the service ID assigned for each Configuration instance (one exists for each DocumentManager). I believe you can also fetch a DM’s configuration via thegetConfiguration()method.