首页  »   Go

Spark 联接 MongoDB

网友分享于:2018-03-19  浏览:0次
Spark 连接 MongoDB
Spark 连接 Mongodb
官方地址:https://www.mongodb.com/products/spark-connector

使用时候遇到一个问题,就是通过MongodbConnector 连接 Mongodb 时候,如果mongodb 是有密码验证的,一直不能通过验证:
一直报错:not authorized on admin to execute command

引用
[WARN ] 2018-03-07 09:53:42,445 com.mongodb.spark.rdd.partitioner.MongoSamplePartitioner - Could not get collection statistics. Server errmsg: Command failed with error 13: 'not authorized on admin to execute command { collStats: "yw_route", $queryOptions: { $readPreference: { mode: "secondaryPreferred" } } }' on server x.x.x.x:x. The full response is { "ok" : 0.0, "errmsg" : "not authorized on admin to execute command { collStats: \"yw_route\", $queryOptions: { $readPreference: { mode: \"secondaryPreferred\" } } }", "code" : 13 }


查找了很长时间,终于找到了解决方法:
配置mongodb uri 如下:

引用
mongodb://USER:PW@HOST:PORT,HOST1:PORT1/DB.COLLECTION?authSource=admin

验证通过,也可以查询数据了

相关解决方案

最新解决方案