[英]Doctrine MongoDB use without ODM
I am using Doctrine MongoDB within Symfony2, but now I want to do some things which for me are easier without the ODM, how can I get the MongoClient or MongoCollection object?我在 Symfony2 中使用 Doctrine MongoDB,但现在我想做一些在没有 ODM 的情况下对我来说更容易的事情,我如何获得 MongoClient 或 MongoCollection 对象?
I want to use MongoDB in the old-fashioned way like: http://php.net/manual/en/mongocollection.find.php我想以老式的方式使用 MongoDB,例如: http : //php.net/manual/en/mongocollection.find.php
You can get the MongoClient
from the DocumentManager
using您可以使用从
DocumentManager
获取MongoClient
$mongoClient = $dm->getConnection()->getMongo();
Similarly, you can get a MongoCollection
instance for document class className using同样,您可以使用文档类className获取
MongoCollection
实例
$mongoCollection = $dm->getDocumentCollection('className')->getMongoCollection();
or more simply或者更简单
$mongoCollection = $dm->getConnection()->getMongo()
->selectCollection('collectionName');
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.