doctrine-odm

How to replace an element in an array field in mongodb

北城余情 提交于 2019-12-12 05:32:21
问题 Field tags is array in scenes document. I wanna replace element 'Bad' with 'Good' in the array as: db.scenes.update({ 'tags': 'Bad' }, { $set: { 'tags.$' : 'Good' } }, { 'multi':true}); I don't know how to do it in doctrine. I tried $dm->createQueryBuilder('SceneBundle:Scene') ->update() ->field('tags.$')->set($tag) ->field('tags')->equals($oldTag) ->multiple(true) ->getQuery() ->execute(); but not work. Thanks. 回答1: There isn't a single replace function for this, but you can do it in one

Symfony2 + Need to use the regular expression in doctrine's mongodb ODM to check case insensitive check

时光怂恿深爱的人放手 提交于 2019-12-12 05:26:38
问题 I want to do the case insensitive check for the query. previously I am using MongoRegex as describe in the this ticket But as per the Php.net this is now deprecated, so can't use it, they suggest to use MongoDB\BSON\Regex but I am not sure how use this in symfony2. but it throws class not found exception if I try to use it. Please let me know the possible solution. Or any other way to do the case insensitive check in the ODM custom query (may be in field function) Thank you so much. 回答1: I

Index not created

我与影子孤独终老i 提交于 2019-12-12 04:26:51
问题 I have a document with an index defined. /** @ODM\Document */ class Stat { /** @ODM\Id(strategy="NONE", type="int") */ private $id; /** @ODM\Field(type="string") */ private $period; /** @ODM\ReferenceOne(targetDocument="Player") */ private $player; /** @ODM\Field(type="string") @ODM\Index */ private $statType; However, when I look at the indexes created in the collection, the only index is the _id. To save the document I'm doing: $stat = new Documents\Stat(); $stat->setId(1); $stat->setPlayer

Symfony, ODM: how to set multiply ids annotation

眉间皱痕 提交于 2019-12-12 02:18:00
问题 So the question is how to provide two or more identifiers keys? I couldn't find any answers on this question in google search... Here is example: class Customer { /** * @ODM\Id * * @JMS\Expose * @JMS\Type("string") * */ protected $id; /** * @var integer * @ODM\Id(strategy="INCREMENT") * * @JMS\Expose * @JMS\Type("integer") * */ protected $customerId; So in this case I have second id which increment as I wrote, but first id became null. If I remove and write just * @ODM\Field(type="integer")

Lazy load between referenced documents on MongoDB with Doctrine ODM

与世无争的帅哥 提交于 2019-12-11 19:19:19
问题 Helo, firstly, please excuse my English, is not very good. I am migrating the data container of a Symfony2 application to MongoDB, before that it run with MySQL. I added the DoctrineMongoDBBundle and "almost everything" works perfectly. I have some references between documents in which I would like to keep the "lazy load" pattern offered by the Doctrine ORM. I have read the official documentation for Doctrine ODM, http://docs.doctrine-project.org/projects/doctrine-mongodb-odm/en/latest

MongoDB+Doctrine How to use find with pattern matching

南笙酒味 提交于 2019-12-11 10:29:23
问题 I am using Mongo DB with doctrine. I want to do pattern matching like below db.user_logs.find({ "recipientName": /user1/i }) without using MongoRegex class $qb->field('recipientEmail')->equals(new \MongoRegex('/.*'.$textToSearch.'.*/i')); purpose is to reach solution without creating class (if possible) 回答1: Not sure this is the best way, but it works: $qb->where("function(){ var patt = /".$textToSearch."/i; return patt.test(this.recipientEmail);}"); 来源: https://stackoverflow.com/questions

Doctrine Query from Mysql

浪子不回头ぞ 提交于 2019-12-10 17:38:03
问题 I want to create a Doctrine Query: (Doctrine 2.3) SELECT * FROM `car` WHERE `plate` like '%' AND (`datetime` BETWEEN '2013-03-13 22:20:18' AND '2013-03-13 22:20:20') OR (`datetime` BETWEEN '2013-03-13 15:10:18' AND '2013-03-13 15:10:16') I tried the following but its not working: $qry = $this->manager()->createQueryBuilder() ->from($this->entity, 'e') ->select('e'); $qry->where('e.plate like :plate'); $qry->setParameter('plate', $plate); $qry->andWhere( qry->expr()->between( 'e.datetime', '

MongoDB/doctrine: can't nest $or in $and

家住魔仙堡 提交于 2019-12-09 17:58:26
问题 I'm having trouble nesting multiple two-operand $or operations within an $and operation. The conclusion of this discussion sounds similar what I need, but I'm unable to get it to work. Here's JavaScript of what I'm trying to do: db.Business.find( { $and: [ { $or: [{nm: /American/}, {dsc: /American/}] }, { $or: [{nm: /Mega/}, {dsc: /Mega/}] } ] } ) That works in the MongoDB interactive shell. And here's some PHP that looks ok to me but doesn't work (causes infinite recursion where indicated):

Symfony2 dynamic forms mongodb

試著忘記壹切 提交于 2019-12-08 19:23:28
Following the example as documented in the following http://symfony.com/doc/current/cookbook/form/dynamic_form_generation.html I need to populate subcategory field according to the category selection. I don't understand why this error at /article/create: FatalErrorException: Error: Call to a member function getSubCategories() on a non-object the Form : namespace Cc\HitoBundle\Form\Type; … class ArticleType extends AbstractType { private $registrationArticleListener; public function __construct(RegistrationArticleListener $registrationArticleListener) { $this->registrationArticleListener =

batch orientdb sql in php

喜夏-厌秋 提交于 2019-12-08 12:54:41
问题 i want this in php how can i do. I does not find any library which supports batch sql in php my one of main reason of choosing orient db is its batch features but for php i found nothing please help. I have downloaded doctrine/odm as well AntonTerekhov_OrientDB-PHP from GitHub I am able run this batch sql from studio:- let $u=select from person where id=1 let $f=select expand(out(Friend)) from $u[0] let $a=create vertex posts set created_by=$u[0],text="Hello............lllll" let $pbedge