Search code examples
mongodbsymfonyphp-mongodb

Fill mongoDB with Fixtures data from symfony 3.2


I'm working on a Symfony project, and I'm trying to fill some fixtures data to mongoDB, that's what I did :

<?php

namespace FrontOfficeBundle\DataFixtures\ORM;

use FrontOfficeBundle\Document\Customer;
use Doctrine\Bundle\FixturesBundle\Fixture;
use Doctrine\Common\Persistence\ObjectManager;

class Fixtures extends Fixture
{
    public function load(ObjectManager $manager)
    {
        $customer = new Customer();
        $customer->setName("Ben Abdallah");
        $customer->setSurename("Wajdi");
        $customer->setUsername("wajdibenabdallah");
        $customer->setEmail("wajdi.benabdallah@smarttouchtunisie.com");
        $customer->setPhone("28812010");
        $customer->setPassword("");

        $manager->flush();
    }
}

php bin/console doctrine:mongodb:fixtures:load

and then i got back these results :

Careful, database will be purged. Do you want to continue (y/N) ?y
  > purging database
  > loading Doctrine\Bundle\FixturesBundle\EmptyFixture
  > loading FrontOfficeBundle\DataFixtures\ORM\Fixtures

But nothing has happened in the database (still empty).

I'am using :

  • ubuntuu 16.04
  • Symfony 3.2
  • MongoDB 3.4.4
  • PHP 7.0.23

Any ideas ? Thanks you.


Solution

  • You need to persist the $customer object:

    $manager->persist($customer);   // Store in database.
    

    Can you try that?