doukengzi3517 2013-11-03 17:31
浏览 45

Doctrine ODM,MongoDB,Symfony2 - 插入文档会创建两个数据库条目,应该创建一个

I'm new to Symfony 2 with Mongo (I've used Symfony before and I used MongoDB before, just not them together).

I have this code in Symfony 2:

$dm = $this->container->get('doctrine_mongodb');
$manager = $dm->getManager();
$pain = new Pain();
$pain->setScale(5);
$pain->setDateStart(new \DateTime());    
$manager->persist($pain);
$manager->flush();

Pretty basic Symfony stuff. But running this code once creates two database entries like this:

> db.Resources.find();
{ "_id" : ObjectId("5276842640b59ece04000000"), "scale" : 5, "dateStart" : ISODate("2013-11-03T17:13:10Z"), "type" : "pain" }
{ "_id" : ObjectId("5276842740b59ecd04000004"), "scale" : 5, "dateStart" : ISODate("2013-11-03T17:13:11Z"), "type" : "pain" }

Here is my config.yml:

doctrine_mongodb:
connections:
    default:
        server: mongodb://localhost:27017
        options: {}
default_database: znmj
document_managers:
    default:
        auto_mapping: true

And here's the Pain class:

/**
 * @MongoDB\Document(collection="Resources")
 */
class Pain
{
/**
 * @MongoDB\Id(strategy="auto")
 */
protected $id;  

/**
 * @var integer
 * @MongoDB\Int
 */
protected $scale;

    // getters and setters below
}

I really can't figure out how to handle this issue or debug it. I can get 0 or 2 entries in the database. I Googled a lot for this, and couldn't find anything even remotely related.

Any ideas on what may be causing the problem?

UPDATE: And of course the culprit was <link rel="shortcut icon" href=""> This is a great lesson in debugging.

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 linux驱动,linux应用,多线程
    • ¥20 我要一个分身加定位两个功能的安卓app
    • ¥15 基于FOC驱动器,如何实现卡丁车下坡无阻力的遛坡的效果
    • ¥15 IAR程序莫名变量多重定义
    • ¥15 (标签-UDP|关键词-client)
    • ¥15 关于库卡officelite无法与虚拟机通讯的问题
    • ¥15 目标检测项目无法读取视频
    • ¥15 GEO datasets中基因芯片数据仅仅提供了normalized signal如何进行差异分析
    • ¥100 求采集电商背景音乐的方法
    • ¥15 数学建模竞赛求指导帮助