开发者

Mongo Insert Fails on Amazon EC2

开发者 https://www.devze.com 2023-03-31 12:28 出处:网络
I\'m new to Amazon EC2. I\'ve been trying to insert into Mongo in an Amazon EC2 instance from another EC2 instance that hosts the web server.

I'm new to Amazon EC2. I've been trying to insert into Mongo in an Amazon EC2 instance from another EC2 instance that hosts the web server.

My code:

<?php
  $m = new Mongo("mongodb://test:test@<ec2 internal ip of MongoDB instance:27017>/mydb");
  $db = $m->mydb;
  $ac = $db->test_collection;
  try {
    // In the following line, instead of "save()", if I try to
    // access the collection using cursor and then iterate through,
    // it fetches the data without any problem.
    $ret = $ac->save(array("name"=>"Mouli")); // fails here
    echo "All set.";
  }
  catch(MongoCursorException $e) {
    echo "M Error:"; echo $e->getMessage();
  }
  catch(Exception $e) {
    echo "Error:";echo $e->getMessage();
  }

Few points:

  1. The above code exactly works fine if I try to run from my dev machine using the public ip that Amazon issued us to connect to MongoDB instance.
  2. Also, tried the same code from web server EC2 ins开发者_运维技巧tance with both public and internal IP; read works in both cases but save fails.

Port 27017 has been updated in Security Groups.

Not sure if there's any other specific setting need to be taken care of for writing into the db from another EC2 instance, since the read is working fine for that scenario.

Your help is greatly appreciated.


Solved! Unfortunately, it's due to a bug introduced in PHP mongo client 1.2.3. After upgrading to 1.2.4, it worked without any issues.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号