mirror of
https://github.com/alibaba/DataX.git
synced 2025-05-03 02:19:56 +08:00
mongo writer support config authentication db name
This commit is contained in:
parent
db01f12463
commit
a47b3eaf57
@ -132,6 +132,8 @@ MongoDBWriter通过Datax框架获取Reader生成的数据,然后将Datax支持
|
||||
* address: MongoDB的数据地址信息,因为MonogDB可能是个集群,则ip端口信息需要以Json数组的形式给出。【必填】
|
||||
* userName:MongoDB的用户名。【选填】
|
||||
* userPassword: MongoDB的密码。【选填】
|
||||
* dbName: MongoDB数据库【选填】
|
||||
* authDb: MongoDB认证数据库【选填】
|
||||
* collectionName: MonogoDB的集合名。【必填】
|
||||
* column:MongoDB的文档列名。【必填】
|
||||
* name:Column的名字。【必填】
|
||||
|
@ -25,6 +25,10 @@ public class KeyConstant {
|
||||
* mongodb 数据库名
|
||||
*/
|
||||
public static final String MONGO_DB_NAME = "dbName";
|
||||
/**
|
||||
* mongodb 认证数据库名
|
||||
*/
|
||||
public static final String MONGO_AUTHDB = "authDb";
|
||||
/**
|
||||
* mongodb 集合名
|
||||
*/
|
||||
|
@ -66,11 +66,12 @@ public class MongoDBWriter extends Writer{
|
||||
private String password = null;
|
||||
|
||||
private String database = null;
|
||||
private String authDb = null;
|
||||
private String collection = null;
|
||||
private Integer batchSize = null;
|
||||
private JSONArray mongodbColumnMeta = null;
|
||||
private JSONObject writeMode = null;
|
||||
private static int BATCH_SIZE = 1000;
|
||||
private static final int BATCH_SIZE = 1000;
|
||||
|
||||
@Override
|
||||
public void prepare() {
|
||||
@ -320,8 +321,11 @@ public class MongoDBWriter extends Writer{
|
||||
this.userName = writerSliceConfig.getString(KeyConstant.MONGO_USER_NAME);
|
||||
this.password = writerSliceConfig.getString(KeyConstant.MONGO_USER_PASSWORD);
|
||||
this.database = writerSliceConfig.getString(KeyConstant.MONGO_DB_NAME);
|
||||
this.authDb = writerSliceConfig.getString(KeyConstant.MONGO_AUTHDB);
|
||||
// 认证源
|
||||
String authSource = Strings.isNullOrEmpty(authDb) ? database : authDb;
|
||||
if(!Strings.isNullOrEmpty(userName) && !Strings.isNullOrEmpty(password)) {
|
||||
this.mongoClient = MongoUtil.initCredentialMongoClient(this.writerSliceConfig,userName,password,database);
|
||||
this.mongoClient = MongoUtil.initCredentialMongoClient(this.writerSliceConfig,userName,password,authSource);
|
||||
} else {
|
||||
this.mongoClient = MongoUtil.initMongoClient(this.writerSliceConfig);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user