简体   繁体   中英

search in mongodb problems (local/remote)

I have a problem with a mongodb database and a php script on two different environments.

First environment have x86 mongodb version on localhost. Second environment have x64 mongodb version on remotly server.

The php script it's the same (it's on x86 mongodb machine).

    $mongo = new Mongo("mongodb://IP:27017");
    pr($mongo);
    $db_mongo = $mongo->my_database;
    $collection = $db_mongo->my_collection;
    $where  = array('$and'=> array(array("NAME" => new MongoRegex("/.*{$name}.*/i")), array("STATUS" => 0)));
    $object_results = $collection->find($where)->timeout(100000);

IP it's 127.0.0.1 for localhost and 188.... for remote server. On both mongodb databases are the same collections with same data (import/export).

mongo object ist's also the same for the both servers....connected 1

Mongo Object
(
    [connected] => 1
    [status] => 
    [server:protected] => 
    [persistent:protected] => 
)

I don't understand why on local connection it return some results, but on remote server it doesn't return records...

PS iptables down... i can access database (connected => 1)

Firstly, if you're using a driver version of 1.3 or newer, I would suggest using the MongoClient class in lieu of Mongo (since deprecated).

Since you've specified 100,000 milliseconds with MongoCursor::timeout() , the script should not hang longer than 100 seconds, as the driver should throw a MongoCursorTimeoutException if it does not receive a response from the server within that time.

To debug this a bit further, I would suggest first lowering your timeout value, and then comparing the output of MongoCursor::explain() from each server. The explain output should make it clear if one server is not using an index for its query, as Sammaye hypothesized above.

Additionally, adding the following will allow you to collect logs for the driver's internal activity:

MongoLog::setModule(MongoLog::ALL);
MongoLog::setLevel(MongoLog::ALL);
MongoLog::setCallback('print_mongo_log');
function print_mongo_log($a, $b, $c) { echo $c, "\n"; }

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM