Giter VIP home page Giter VIP logo

doctrinemongodbbundle's Introduction

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!

doctrinemongodbbundle's People

Contributors

avalanche123 avatar poulikov avatar

Stargazers

 avatar  avatar  avatar  avatar

Watchers

 avatar

Forkers

cwallenpoole

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.