mongodb atlas建议使用connectionstring。
ConnectionString connectionString = new ConnectionString(given string);
MongoClientSettings settings = MongoClientSettings.builder()
.applyConnectionString(connectionString)
.build();
MongoClient mongoClient = MongoClients.create(settings);
MongoDatabase database = mongoClient.getDatabase("test");
不过,我得到了这个错误。 java.lang.NoClassDefFoundError: Failed resolution of: Ljavax/naming/directory/InitialDirContext;
这是我的依赖项。
dependencies {
implementation 'org.mongodb:mongodb-driver-sync:4.0.5'
// implementation 'org.mongodb:mongo-java-driver:2.13.2'
implementation 'androidx.appcompat:appcompat:1.3.0'
implementation 'com.google.android.material:material:1.3.0'
implementation 'com.google.android.gms:play-services-maps:17.0.1'
implementation 'androidx.constraintlayout:constraintlayout:2.0.4'
implementation 'androidx.preference:preference:1.1.1'
testImplementation 'junit:junit:4.+'
androidTestImplementation 'androidx.test.ext:junit:1.1.2'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.0'
}
我已将permission.internet包含在我的清单中。对于依赖项,我尝试使用MongoJava驱动程序工具,如mongoclienturi,但连接超时。
暂无答案!
目前还没有任何答案,快来回答吧!