简体   繁体   English

Mongo插入在Amazon EC2上失败

[英]Mongo Insert Fails on Amazon EC2

I'm new to Amazon EC2. 我是Amazon EC2的新手。 I've been trying to insert into Mongo in an Amazon EC2 instance from another EC2 instance that hosts the web server. 我一直在尝试从托管Web服务器的另一个EC2实例插入到Amazon EC2实例的Mongo中。

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. 如果我尝试使用Amazon发行给我们的公共IP从我的开发机上运行以连接到MongoDB实例,则上述代码可以正常工作。
  2. Also, tried the same code from web server EC2 instance with both public and internal IP; 另外,还尝试使用公共IP和内部IP从Web服务器EC2实例尝试相同的代码; read works in both cases but save fails. 两种情况下都可以读取,但是保存失败。

Port 27017 has been updated in Security Groups. 端口27017已在安全组中更新。

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. 不知道从其他EC2实例写入数据库是否需要照顾其他特定设置,因为在这种情况下读取工作正常。

Your help is greatly appreciated. 非常感谢您的帮助。

Solved! 解决了! Unfortunately, it's due to a bug introduced in PHP mongo client 1.2.3. 不幸的是,这是由于PHP mongo client 1.2.3中引入的错误所致。 After upgrading to 1.2.4, it worked without any issues. 升级到1.2.4后,它可以正常工作。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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