-
Type: Task
-
Resolution: Won't Fix
-
Priority: Major - P3
-
None
-
Affects Version/s: None
-
Component/s: None
-
None
I trying to connect server but I am getting this error
Error
_com.mongodb.MongoTimeoutException:
Timed out after 3000 ms while waiting to connect. Client view of cluster state is
{type=UNKNOWN,
servers=[{
address=<server_address>:27017,
type=UNKNOWN,
state=CONNECTING,
exception=
,
caused by
}]_
This is my Code:
_MongoClientOptions.Builder o = MongoClientOptions.builder().serverSelectionTimeout(3000);
MongoCredential credential = MongoCredential.createCredential("admin", "<database_name>","admin".toCharArray());
// Creating a Mongo client
MongoClient mongo = new MongoClient( new ServerAddress("<server_address>" , 27017),credential,o.build());
System.out.println("Connected to the database successfully ");
// Accessing the database
MongoDatabase database = mongo.getDatabase("<database_name>");
System.out.println("Collection created successfully");
// Retrieving a collection
MongoCollection<Document> collection = database.getCollection("<collection_name>");
System.out.println("Collection sampleCollection selected successfully ");
//Getting the iterable object
FindIterable<Document> iterDoc = collection.find();
int i = 1;
String s = null;
// Getting the iterator
Iterator it = null;
try {
it = iterDoc.iterator();
while (it.hasNext())
} catch (Exception e)
{ e.printStackTrace(); Log.i("TAG",""+e); }return s;_
- is duplicated by
-
JAVA-1958 SCRAM-SHA1 authentication is not available on Android
- Closed