MongoCursor::doQuery

(PECL mongo >=0.9.0 <1.6.0)
Execute the query.
protected void MongoCursor::doQuery ( void )

This function actually queries the database. All queries and commands go through this function. Thus, this function can be overridden to provide custom query handling.

This handles serializing your query, sending it to the database, receiving a response, and deserializing it. Thus, if you are planning to override this, your code should probably call out to the original to use the existing functionality (see the example below).

Returns:

NULL.

Please do not use me.

Exception:

Throws MongoConnectionException if it cannot reach the database.

Changelog:
1.2.11

Emits E_DEPRECATED when used.

Examples:
MongoCursor::doQuery() example

You could override this function to attempt a query on a secondary and, if that fails, try it again on the primary.

<?php

class MyCursor extends MongoCursor {

    protected function doQuery() {

        $this->slaveOkay();

        try {
            MongoCursor::doQuery();
        }
        catch(MongoCursorException $e) {
            $this->slaveOkay(false);
            MongoCursor::doQuery();
        }
    }
}

?>

doc_php
2016-02-24 16:20:42
Comments
Leave a Comment

Please login to continue.