Builds the MongoDB cursor for this query.
@param Connection $db the MongoDB connection used to execute the query.
@return \MongoDB\Driver\Cursor mongo cursor instance.
326021
public function buildCursor($db = null)
    {
        $this->prepare();

        $options = $this->options;
        if (!empty($this->orderBy)) {
            $options['sort'] = $this->orderBy;
        }
        $options['limit'] = $this->limit;
        $options['skip'] = $this->offset;

        $cursor = $this->getCollection($db)->find($this->composeCondition(), $this->select, $options);

        return $cursor;
    }
1281219
public function configure($cursor = [])
    {
        return Query::create($this->orders, $cursor, $this->limit, $this->backward, $this->exclusive, $this->seekable, $this->builder);
    }
396290
public function exec(Db $db) {
        $options = [
            'limit' => $this->limit,
            'offset' => $this->offset
        ];

        $r = $db->get($this->from, $this->where, $options);
        return $r;
    }
576037
private function getDatabasePlatform(Connection $connection)
    {
        try {
            return $connection->getDatabasePlatform();
        } catch (DriverException $driverException) {
            throw new DBALException(
                'An exception occured while establishing a connection to figure out your platform version.' . PHP_EOL .
                "You can circumvent this by setting a 'server_version' configuration value" . PHP_EOL . PHP_EOL .
                'For further information have a look at:' . PHP_EOL .
                'https://github.com/doctrine/DoctrineBundle/issues/673',
                0,
                $driverException
            );
        }
    }
5676
private function lockColumnsExist(Connection $db)
    {
        $schema = $db->getSchemaManager()->listTableColumns($this->table);
        return isset($schema['lockid']);
    }
658769
private function reserveNext(array $next, Connection $db)
    {
        $lockID = $this->getLockID();

        // First update the table
        try {
            $date = new \DateTime('now');
            $date->setTimestamp($date->getTimestamp() + $this->timeout);

            if (!$db->update($this->table, [
                $this->lockColumn => $lockID,
                $this->lockTimeoutColumn => $date->format('Y-m-d H:i:s')
            ], $next)
            ) {
                return false;
            }
        } catch (\Exception $e) {
            return false;
        }

        return $this->matchingLock($lockID, $next, $db);
    }
359140
public function execute(Server $server)
    {
        $cursor = $server->executeCommand($this->databaseName, $this->command, $this->createOptions());

        if (isset($this->options['typeMap'])) {
            $cursor->setTypeMap($this->options['typeMap']);
        }

        return $cursor;
    }
316311
public DBCursor<T> find(T query) throws MongoException {
        return new DBCursor<T>(this, dbCollection.find(convertToBasicDbObject(query)));
    }
955841
protected function selectSQLDriver($connection)
    {
        switch (strtolower($connection)) {
            case 'mysql':
                $this->db = [
                    'driver'   => 'pdo_mysql',
                    'host'     => env('DB_HOST', '127.0.0.1'),
                    'port'     => env('DB_PORT', '3306'),
                    'dbname'   => env('DB_DATABASE', 'teamelf'),
                    'user'     => env('DB_USERNAME', 'teamelf'),
                    'password' => env('DB_PASSWORD', 'teamelf'),
                    'charset'  => 'UTF8'
                ];
                break;
            default:
                throw new Exception($connection . 'has not been supported yet! use [mysql] instead!');
        }
    }
779821
public function insert($db = null)
    {
        $this->getDAO($this->getDB($db))->save($this);
        return $this;
    }
669308
public static function getQueryBuilder(Connection $connection)
    {
        switch ($connection->getDriver()->getName()) {
            case 'pdo_mysql':
                $adapter = new Database\Mysql\Adapter($connection);
                break;

            case 'pdo_sqlite':
                $adapter = new Database\Sqlite\Adapter($connection);
                break;

            case 'pdo_pgsql':
                $adapter = new Database\Pgsql\Adapter($connection);
                break;

            default:
                throw new NotSupportedException('Unknown driver');
        }

        $lookupBuilder = new LookupBuilder();
        $lookupBuilder->addLookupCollection($adapter->getLookupCollection());

        return new QueryBuilder($connection, $adapter, $lookupBuilder);
    }
1137128
private function getMongoClient() {
        if ($this->mongoClient === null) {
            try {
                $this->mongoClient = new MongoClient($this->params['server'], $this->params['options']);
            } catch (MongoException $e) {
                throw new DatabaseException('Could not connect to database', 500, $e);
            }
        }

        return $this->mongoClient;
    }
1294137
private function createExport($db)
    {
        Service::$log->msg(sprintf('Mongodb: exporting "%s" database.', $db['Database']));

        $cmd = 'mongodump';

        if (!isset($db['Database'])) {
            throw new \Exception(sprintf('Missing "Database" parameter for one of the MongoDatabases'));
        }

        $cmd .= ' --db ' . $db['Database'];

        if (!isset($db['Host'])) {
            throw new \Exception(sprintf('Missing "Host" parameter for "%s" database', $db['Database']));
        }

        $host = explode(':', $db['Host']);

        $cmd .= ' --host ' . $host[0];

        if (isset($host[1])) {
            $cmd .= ' --port ' . $host[1];
        }

        if (isset($db['Username']) && !empty($db['Username'])) {
            $cmd .= ' --username ' . $db['Username'];
        }

        if (isset($db['Password']) && !empty($db['Password'])) {
            $cmd .= ' --password ' . $db['Password'];

            if(!isset($db['AuthenticationDatabase'])){
                $cmd .= ' --authenticationDatabase admin';
            }else{
                $cmd .= ' --authenticationDatabase '.$db['AuthenticationDatabase'];
            }
        }

        // create a folder for this database export
        $folderName = $this->tempFolder . $db['Database'] . '-' . date('Y-m-d');
        $cmd .= ' --out ' . $folderName;

        // mask password from log command
        if(isset($db['Password'])){
            $logCommand = str_replace(' --password ' . $db['Password'], ' --password xxxxxx', $cmd);
        }else{
            $logCommand = $cmd;
        }


        Service::$log->msg(sprintf('Mongodb: export command ' . $logCommand));

        $return = system($cmd);

        Service::$log->msg(sprintf('Mongodb: '.$return));
        Service::$log->msg(sprintf('Mongodb: database export done'));

        Cleanup::addToQueue($folderName, Cleanup::TYPE_DIR);

        return $folderName;
    }
882486
def get_mongo_cursor(self, bulk=False):
        
        try:
            if self.host:
                if self.port:
                    client = MongoClient(self.host, self.port)
                else:
                    client = MongoClient(
                        self.host, MongoCollection.DEFAULT_PORT)
            else:

                client = MongoClient(self.mongo_uri)

            db = client[self.db_name]
            cursor = db[self.collection]

            if bulk:
                try:
                    return cursor.initialize_unordered_bulk_op()
                except Exception as e:
                    msg = "Mongo Bulk cursor could not be fetched, Error: {error}".format(
                        error=str(e))
                    raise Exception(msg)

            return cursor

        except Exception as e:
            msg = "Mongo Connection could not be established for Mongo Uri: {mongo_uri}, Database: {db_name}, Collection {col}, Error: {error}".format(
                mongo_uri=self.mongo_uri, db_name=self.db_name, col=self.collection, error=str(e))
            raise Exception(msg)
638880
public function db($db = null)
    {
        if ($db === null)
        {
            return $this->_db;
        }
        $this->_db = $db;

        return $this;
    }
152382
@Override
    public DBCursor cursor(DBCollection dbCollection) {
        logger.debug("Executing {} for {} cursor", delegate, dbCollection.getFullName());

        DBCursor dbCursor = delegate.cursor(dbCollection);

        if (logger.isDebugEnabled()) {
            StringBuilder sb = new StringBuilder();
            DBObject plan = dbCursor.explain();

            sb.append("MongoDB query plan:\n");
            sb.append("\tcursor = \"").append(plan.get("cursor")).append("\"\n");
            sb.append("\tnscanned = \"").append(plan.get("nscanned")).append("\"\n");
            sb.append("\tn = \"").append(plan.get("n")).append("\"\n");
            sb.append("\tmillis = \"").append(plan.get("millis")).append("\"\n");

            logger.debug(sb.toString());
        }

        return dbCursor;
    }
1058133
public function selectCollection($db, $collection)
    {
        $this->initialize();
        return $this->selectDatabase($db)->selectCollection($collection);
    }