简体   繁体   English

从Pig连接到Mongodb副本集URI

[英]Connecting from Pig to a Mongodb Replica Set URI

I'm trying to store data from Pig into a Mongodb database with replica set of two hosts: 我正在尝试将Pig中的数据存储到具有两个主机副本集的Mongodb数据库中:

STORE out INTO 'mongodb://user:pass@mongoserver1.com:27017,mongoserver2.com:27017/my_db.my_collection?replicaSet=set-1234
USING com.mongodb.hadoop.pig.MongoUpdateStorage('{"_id":"\$id"}', '{\$set:{"_id":"\$uid","data":"\$data"}}','id:chararray,data:chararray','','{upsert:true}');

But I'm getting the following exception: 但是我收到以下异常:

pig script failed to validate: java.lang.IllegalArgumentException:
java.net.URISyntaxException: Relative path in absolute URI: mongoserver2.com:27017/my_db.my_collection%3FreplicaSet=set-1234 

Which seems to be related to a problem parsing correctly the MongoClientURI format. 这似乎与正确解析MongoClientURI格式的问题有关。

Is there a way to connect to from Pig to a MongoDB multi-host replica set? 有没有办法从Pig连接到MongoDB多主机副本集?

As long as you specify the replica set name in the MongoURI, the MongoDB Java Driver will automatically detect replica set failover and discover the primary. 只要您在MongoURI中指定副本集名称,MongoDB Java驱动程序就会自动检测副本集故障转移并发现主要副本。 Even if the address of the (primary) machine was not listed in the URI connection string. 即使(主要)计算机的地址未在URI连接字符串中列出。

You can test this by specifying the secondary for example : 您可以通过指定次要实例来进行测试, 例如

STORE out INTO     
  'mongodb://user:pass@mongoserver2.com:27017/my_db.my_collection?replicaSet=replicaSetName'
USING com.mongodb.hadoop.pig.MongoInsertStorage('', '');

The behaviour above is tested on: mongo-java-driver-3.2.2.jar , mongo-hadoop-pig-1.5.0.jar and mongo-hadoop-core-1.5.0.jar . 在以下行为上测试了上述行为: mongo-java-driver-3.2.2.jarmongo-hadoop-pig-1.5.0.jarmongo-hadoop-core-1.5.0.jar

Note that in your example you had mistyped replicaSet in the URI, although it may be a typo while writing question here. 请注意,在您的示例中,您在URI中输入了replicaSet错误的replicaSet ,尽管在此处编写问题时可能是拼写错误。

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

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