问题描述
我使用的是symfony2和mongodb,直到今天一切都还好,但是我创建了一个新文档,突然出现了这个错误:
I'm using symfony2 and mongodb, until today, everything is OK, but I create a new document, and suddenly, appears this error :
$dm = $this->get('doctrine.odm.mongodb.document_manager');
$_repo = $dm->getRepository('CantaoCustomerBundle:CustomerTags');
$_repo->findOneByCustomer($customer);
$customer
没问题,存储库为空,我的文档类如下:
The $customer
it's OK, the repository is empty, and my document class is like this :
/**
* @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;
有人可以帮我吗,有什么主意,我尝试了一切,但似乎没有任何效果
Can anyone help me, have some idea, I tried everything and nothing seems to work
推荐答案
可能是您要保留对象私有属性.
It could be that you're trying to persist an object private attribute.
如果不是这种情况,调试的好方法是关闭零长度密钥检查,以便您实际上可以通过检查将其写入mongo中的内容来进行调试.
If that's not the case a good way to debug is to shut off the zero-length key check so that you can actually debug by checking what it's being written into mongo.
代码:1
您试图将"保存为键.您通常不应该这样做. "可能会使子对象访问混乱,并且在内部由MongoDB使用.但是,如果您确实需要,可以在php.ini文件中将mongo.allow_empty_keys设置为true,以覆盖此健全性检查.如果您对此进行了覆盖,强烈建议您将错误检查设置为严格",以避免字符串插值错误.
You tried to save "" as a key. You generally should not do this. "" can mess up subobject access and is used by MongoDB internally. However, if you really want, you can set mongo.allow_empty_keys to true in your php.ini file to override this sanity check. If you override this, it is highly recommended that you set error checking to strict to avoid string interpolation errors.
http://php.net/手册/zh-CN/mongo.configuration.php#ini.mongo.allow-empty-keys
这篇关于MongoException:不允许使用零长度的键,您是否使用了带双引号的$?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!