doctrine mongodb native query 1

doctrine mongodb native query

/** @var DocumentManager $documentManager */
$documentManager = $this->container
	->get('doctrine_mongodb')
	->getManager();

$mongoClient = $documentManager->getConnection()->getMongoClient();

$db = $mongoClient->selectDB('dbname');

$collection = $mongoClient->selectCollection($db, 'collectionName');
$results = $collection->find();

Here is what the above code is Doing:
1. Get the document manager from the service container
2. Get the mongo client from the document manager
3. Select the database
4. Select the collection
5. Find all documents in the collection

### Inserting Documents

Similar Posts