1

I'm trying to start using MongoDB with Doctrine MongoDB ODM 1.1.3 and Laravel 5.4. Everything had been going fine before I removed the database called "doctrine" manually (the default database name I guess) in order to clean up the rubbish in it, so basically I just wanted to remove the database and was hoping that Doctrine will create a new one. Now when I'm trying to call

$mgr->persist($divRoot);
$mgr->flush();

It assigns an ID to the $divRoot object, but doesn't persist it. I.e. when I then call the findAll() method on the repo, it returns nothing. And it doesn't create any databases anymore. The $divRoot has changing fields every time I'm trying to save it. I've got really stuck, please help

UPDATE 1

If I initialize a new DocumentManager specifying a new path to the documents (AnnotationDriver::create($documents)), the ODM works normally persisting and retrieving the documents.

super.t
  • 2,526
  • 7
  • 32
  • 51

1 Answers1

2

I've figured out what was wrong. I was working only with embedded documents whereas it must be at least one root Document. Originally all of them were marked as Documents that's why I was able to persist them, it's nothing to do with the database removal.

So, I was trying to persist a composite consisting out EmbeddedDocuments only.

The solution was to create a root wrapper for the composite marked as Document.

super.t
  • 2,526
  • 7
  • 32
  • 51