/** * Retrieves the Collection object. * * @return Collection */ protected function getCollection() : Collection { $conn = $this->connPool->getConnection(); $database = $conn->defaultDatabase; $collection = $this->schema->collection; return $conn->getRawConnection()->{$database}->{$collection}; }
/** * Register MongoDbConnector within the application. * * @return void */ public function registerConnector() { $config = $this->app->make('config'); MongolidIoc::setContainer($this->app); $connectionString = $this->buildConnectionString(); $connection = new Connection($connectionString); $pool = new Pool(); $eventService = new EventTriggerService(); $eventService->registerEventDispatcher($this->app->make(LaravelEventTrigger::class)); $pool->addConnection($connection); $this->app->instance(Pool::class, $pool); $this->app->instance(EventTriggerService::class, $eventService); $this->app->bind(CacheComponentInterface::class, function ($app) { return new LaravelCacheComponent($app[CacheRepository::class], $app[Serializer::class]); }); $connection->defaultDatabase = $config->get('database.mongodb.default.database', 'mongolid'); }
/** * Get the raw MongoDB connection. * * @return \MongoDB\Client */ public function getConnection() { $this->init(); return $this->connectionPool->getConnection()->getRawConnection(); }