How can I use regular expressions with Doctrine's Mongodb ODM?
问题 I'm trying to use regular expressions to query Mongodb using Doctrine's Mongodb ODM on Symfony 2. I know the PHP mongo driver can do it. However, I don't know how to do this with Doctrine. Do I use the same class? How do I reference MongoRegex from within Symfony? 回答1: This came up a while ago on the doctrine-user mailing list. You can use the \MongoRegex class directly in your ODM queries: $documentRepository->findBy(array( 'foo' => new \MongoRegex('/^bar/'), )); Or if using a query builder: