private function replaceRenameCollection($newName, $dropTarget)
    {
        // create admin db instance
        $adminDb = $this->getDatabase()->getClient()->getDatabase('admin');

        list($targetDatabaseName, $targetCollectionName) = $this->getCompleteCollectionNamespace($newName);

        // rename current collection to target
        $response = $adminDb->executeCommand(array(
            'renameCollection' => $this->getDatabase()->getName() . '.' . $this->getName(),
            'to' => $targetDatabaseName . '.' . $targetCollectionName,
            'dropTarget' => $dropTarget,
        ));

        if ($response['ok'] !== 1.0) {
            throw new Exception('Error: #' . $response['code'] . ': ' . $response['errmsg'], $response['code']);
        }

        // re-init to new db and collection
        $this->database = $this->getDatabase()->getClient()->getDatabase($targetDatabaseName);
        $this->collection = $this->database->getCollection($targetCollectionName)->getMongoCollection();
        $this->collectionName = $this->collection->getName();

        return $this;
    }
private function replaceRenameCollection($newName, $dropTarget)
    {
        // create admin db instance
        $adminDb = $this->getDatabase()->getClient()->getDatabase('admin');

        list($targetDatabaseName, $targetCollectionName) = $this->getCompleteCollectionNamespace($newName);

        // rename current collection to target
        $response = $adminDb->executeCommand(array(
            'renameCollection' => $this->getDatabase()->getName() . '.' . $this->getName(),
            'to' => $targetDatabaseName . '.' . $targetCollectionName,
            'dropTarget' => $dropTarget,
        ));

        if ($response['ok'] !== 1.0) {
            throw new Exception('Error: #' . $response['code'] . ': ' . $response['errmsg'], $response['code']);
        }

        // re-init to new db and collection
        $this->database = $this->getDatabase()->getClient()->getDatabase($targetDatabaseName);
        $this->collection = $this->database->getCollection($targetCollectionName)->getMongoCollection();
        $this->collectionName = $this->collection->getName();

        return $this;
    }
private function replaceRenameCollection ( $ newName , $ dropTarget ) { // create admin db instance $ adminDb = $ this -> getDatabase ( ) -> getClient ( ) -> getDatabase ( 'admin' ) ; list ( $ targetDatabaseName , $ targetCollectionName ) = $ this -> getCompleteCollectionNamespace ( $ newName ) ; // rename current collection to target $ response = $ adminDb -> executeCommand ( array ( 'renameCollection' => $ this -> getDatabase ( ) -> getName ( ) . '.' . $ this -> getName ( ) , 'to' => $ targetDatabaseName . '.' . $ targetCollectionName , 'dropTarget' => $ dropTarget , ) ) ; if ( $ response [ 'ok' ] !== 1.0 ) { throw new Exception ( 'Error: #' . $ response [ 'code' ] . ': ' . $ response [ 'errmsg' ] , $ response [ 'code' ] ) ; } // re-init to new db and collection $ this -> database = $ this -> getDatabase ( ) -> getClient ( ) -> getDatabase ( $ targetDatabaseName ) ; $ this -> collection = $ this -> database -> getCollection ( $ targetCollectionName ) -> getMongoCollection ( ) ; $ this -> collectionName = $ this -> collection -> getName ( ) ; return $ this ; }
Rename collection with optionally dropping previously created target collection

@param string $newName The name of target db and collection ex.: "testdb.newcollection"
@param bool $dropTarget Whether to drop target or not

@return Collection

@throws Exception
Rename collection with optionally dropping previously created target collection