-
Notifications
You must be signed in to change notification settings - Fork 13
Description
Not sure if I am doing this right but I just want to do a find on a collection.
Using the driver the correct databaseName is set.
$collection = (new MongoDB\Client)->test_dev->shifts;
CVarDumper::dump($collection,20,true); die();
MongoDB\Collection#1
(
[MongoDB\Collection:collectionName] => 'shifts'
[MongoDB\Collection:databaseName] => 'test_dev'
[MongoDB\Collection:manager] => MongoDB\Driver\Manager#2
(
)
[MongoDB\Collection:readConcern] => MongoDB\Driver\ReadConcern#3
(
)
[MongoDB\Collection:readPreference] => MongoDB\Driver\ReadPreference#4
(
)
[MongoDB\Collection:typeMap] => array
(
'array' => 'MongoDB\Model\BSONArray'
'document' => 'MongoDB\Model\BSONDocument'
'root' => 'MongoDB\Model\BSONDocument'
)
[MongoDB\Collection:writeConcern] => MongoDB\Driver\WriteConcern#5
(
)
)
Using mongoyii the databaseName is set to test_dev.databaseName.
$collection = Yii::app()->mongodb->selectCollection(Yii::app()->params['mongo_collection']);
CVarDumper::dump($collection,20,true); die();
MongoDB\Collection#1
(
[MongoDB\Collection:collectionName] => 'shifts'
[MongoDB\Collection:databaseName] => 'test_dev.databaseName'
[MongoDB\Collection:manager] => MongoDB\Driver\Manager#2
(
)
[MongoDB\Collection:readConcern] => MongoDB\Driver\ReadConcern#3
(
)
[MongoDB\Collection:readPreference] => MongoDB\Driver\ReadPreference#4
(
)
[MongoDB\Collection:typeMap] => array
(
'array' => 'MongoDB\Model\BSONArray'
'document' => 'MongoDB\Model\BSONDocument'
'root' => 'MongoDB\Model\BSONDocument'
)
[MongoDB\Collection:writeConcern] => MongoDB\Driver\WriteConcern#5
(
)
)
I fixed it like this
/**
* A wrapper for the original processing
* @param string $collectionName
* @param string $databaseName
* @param array $options
* @return \MongoCollection
*/
public function selectCollection($collectionName, $options = [], $databaseName = null)
{
if(!$databaseName){
//$databaseName = $this->selectDatabase()->databaseName;
$databaseName = $this->selectDatabase();
}
return $this->getClient()->selectCollection($databaseName, $collectionName, $options);
}