无法使用php从ubuntu连接到Windows服务器上的Mongodb

I wanted to connect to the MongoDB which is installed in windows server from ubuntu using php. I am trying to connect using the following code but output is nothing even mongoexception is not throwing any error.

$mngo = new Mongo("mongodb://192.168.1.119:27017");
$db = $mngo->selectDB('travelmanagement_qa');

Can anyone please tell me why i am not able to connect? Thank You in advance

A few comments:

  • Please use new MongoClient instead of new Mongo.
  • This should not output anything at all. You're just selecting a database and assigning it to a variable. Is that your whole code snippet?
  • What did you expect the output to be?

To figure out what is actually happening under the hood with connections you can use MongoLog. With this functionality you can track down what the driver is doing internally. You'd use it like:

MongoLog::setLevel(MongoLog::ALL);
MongoLog::setModule(MongoLog::RS);
MongoLog::setCallback( 'printMsgs' );

function printMsgs($a, $b, $msg)
{
    echo $msg, "
";
}