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.