Skip to content
This repository has been archived by the owner on Oct 15, 2019. It is now read-only.

A Symfony2 Bundle to enable mongo document manager service

Notifications You must be signed in to change notification settings

poulikov/DoctrineMongoDBBundle

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

29 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Setup#

Get MongoDB ODM here

Usage

Include the bundle class in your Kernel:

use Symfony\Foundation\Kernel;
use Symfony\Components\DependencyInjection\Loader\YamlFileLoader as ContainerLoader;
use Symfony\Components\Routing\Loader\YamlFileLoader as RoutingLoader;

class YourKernelClass extends Kernel
{
	//...
	public function registerBundles()
	{
		return array(
			new Symfony\Foundation\Bundle\KernelBundle(),
			new Symfony\Framework\WebBundle\Bundle(),
			new Symfony\Framework\ProfilerBundle\Bundle(),
			new Symfony\Framework\ZendBundle\Bundle(),
			new Symfony\Framework\SwiftmailerBundle\Bundle(),
			new Symfony\Framework\DoctrineBundle\Bundle(),
			//...
			new Bundle\DoctrineMongoDBBundle\Bundle(),
		);
	}
	//...
}

Add the following to your yaml configuration file:

mongodb.odm:
  default_document_manager: default
  cache_driver:            array
  document_managers:
    default:
      connection:      mongodb
  connections:
    mongodb:
      server:        localhost/somedatabase

Now in your controller do:

$dm = $this->container->getService('doctrine.odm.document_manager');
//or...
$dm = $this->container->getService('doctrine.odm.default_document_manager');

You could specify multiple document managers:

mongodb.odm:
  default_document_manager: default
  cache_driver:            array
  document_managers:
    default:
      connection:      mongodb
    additional:
      connection:      other_mongo
  connections:
    mongodb:
      server:        localhost/somedatabase
    other_mogno:
      server:        192.168.0.18/other_database

Now you can get either document manager:

$defaultDm = $this->container->getService('doctrine.odm.default_document_manager');
$additionalDm = $this->container->getService('doctrine.odm.additional_document_manager');

Or you could just use default connection params and one document manager:

mongodb.odm: ~

After you have DocumentManager instance, you can use it:

$user = $dm->find('Documents\User', array('name' => 'Bulat S.'));

Full MongoDB ODM documentation is available at doctrine website

Happy Coding!

About

A Symfony2 Bundle to enable mongo document manager service

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 4

  •  
  •  
  •  
  •  

Languages