gpt4 book ai didi

mongodb - MongoException : zero-length keys are not allowed, 你用双引号的 $ 吗?

转载 作者:IT老高 更新时间:2023-10-28 13:25:33 25 4
gpt4 key购买 nike

我用的是symfony2和mongodb,直到今天一切正常,但是我新建一个文档,突然出现这个错误:

"MongoException: zero-length keys are not allowed, did you use $ with double quotes?"

$dm = $this->get('doctrine.odm.mongodb.document_manager');
$_repo = $dm->getRepository('CantaoCustomerBundle:CustomerTags');
$_repo->findOneByCustomer($customer);

$customer 就可以了,仓库是空的,我的文档类是这样的:

    /**
* @MongoDB\ID
**/
private $id;

/**
* @MongoDB\ReferenceOne(targetDocument="Tapronto\Mats\ProductBundle\Document\Tag", cascade={"persist"})
**/
private $tag;

/**
* @MongoDB\ReferenceOne(targetDocument="Tapronto\Mats\CustomerBundle\Document\Customer", cascade={"persist"})
**/
private $customer;

/**
* @MongoDB\Float
**/
private $points;

/**
* @MongoDB\Int
**/
private $viewed;

/**
* @MongoDB\Int
**/
private $brought;

/**
* @MongoDB\Int
**/
private $favorited;

/**
* @MongoDB\Date
* @Gedmo\Timestampable(on="create")
**/
private $createdAt;

/**
* @MongoDB\Date
* @Gedmo\Timestampable(on="update")
**/
private $updatedAt;

任何人都可以帮助我,有一些想法,我尝试了所有方法,但似乎没有任何效果

最佳答案

我只是通过使用引用对象的 ID 而不是引用对象本身作为我的搜索词来解决此问题。

$_repo->findOneByCustomer($customer->getId());

编辑:这并没有引发异常,但它实际上也没有返回任何东西。我尝试使用 new MongoId($id) 建议几个地方( Doctrine MongoDB find by id ),但这也不起作用。最后,我在完整的查询生成器中发现了一些按引用搜索的内容(注意:这使用对象而不是对象的 ID)。

$dm->createQueryBuilder()->find('CantaoCustomerBundle:CustomerTags')
->field('customer')->references($customer)
->getQuery()->execute();

我觉得这应该更简单地完成(就像你最初所做的那样),但这个修复对我有用。

关于mongodb - MongoException : zero-length keys are not allowed, 你用双引号的 $ 吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17024593/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com