Nelze konektor pro sadu replik s řidičem Java, pracuje s ovladačem Node.js

hlasů
0

Zde je, jak jsem se připojit k sady replik s Node.js:

var MongoClient = require('mongodb').MongoClient;

var url = 'mongodb://ec2-54-237-60-17.compute-1.amazonaws.com:27017/test?readPreference=secondary';

MongoClient.connect(url, function(err, db) {
    console.log(err);

    db.collection('apps').find({}).limit(5).toArray(function(err, docs) {
        console.log(docs);
    });
});

a já si 5v konzole, takže to funguje správně. S ovladačem Java tady je to, co mám dělat:

import com.mongodb.MongoClient
import com.mongodb.MongoClientURI
import java.util.ArrayList
import com.mongodb.BasicDBObject

object Main extends App {
    val url = mongodb://ec2-54-237-60-17.compute-1.amazonaws.com:27017/test?readPreference=secondary
    val client = new MongoClient(new MongoClientURI(url))

    val db = client.getDatabase(database)
    val collection = db.getCollection(apps)
    val results = collection.find().limit(5).into(new ArrayList[org.bson.Document]())
}

a já si následující výjimce:

com.mongodb.MongoTimeoutException: Timed out after 30000 ms while waiting for a server that matches ReadPreferenceServerSelector{readPreference=secondary}. Client view of cluster state is {type=REPLICA_SET, servers=[{address=belinda-mongo.localdomain:27017, type=UNKNOWN, state=CONNECTING, exception={com.mongodb.MongoSocketException: belinda-mongo.localdomain}, caused by {java.net.UnknownHostException: belinda-mongo.localdomain}}, {address=detroit-mongo.localdomain:27017, type=UNKNOWN, state=CONNECTING, exception={com.mongodb.MongoSocketException: detroit-mongo.localdomain}, caused by {java.net.UnknownHostException: detroit-mongo.localdomain}}, {address=dione-mongoar.localdomain:27017, type=UNKNOWN, state=CONNECTING, exception={com.mongodb.MongoSocketException: dione-mongoar.localdomain}, caused by {java.net.UnknownHostException: dione-mongoar.localdomain}}, {address=pandora-mongo.localdomain:27017, type=UNKNOWN, state=CONNECTING, exception={com.mongodb.MongoSocketException: pandora-mongo.localdomain}, caused by {java.net.UnknownHostException: pandora-mongo.localdomain}}, {address=riverside-mongo.localdomain:27017, type=UNKNOWN, state=CONNECTING, exception={com.mongodb.MongoSocketException: riverside-mongo.localdomain}, caused by {java.net.UnknownHostException: riverside-mongo.localdomain}}]
com.mongodb.MongoTimeoutException: Timed out after 30000 ms while waiting for a server that matches ReadPreferenceServerSelector{readPreference=secondary}. Client view of cluster state is {type=REPLICA_SET, servers=[{address=belinda-mongo.localdomain:27017, type=UNKNOWN, state=CONNECTING, exception={com.mongodb.MongoSocketException: belinda-mongo.localdomain}, caused by {java.net.UnknownHostException: belinda-mongo.localdomain}}, {address=detroit-mongo.localdomain:27017, type=UNKNOWN, state=CONNECTING, exception={com.mongodb.MongoSocketException: detroit-mongo.localdomain}, caused by {java.net.UnknownHostException: detroit-mongo.localdomain}}, {address=dione-mongoar.localdomain:27017, type=UNKNOWN, state=CONNECTING, exception={com.mongodb.MongoSocketException: dione-mongoar.localdomain}, caused by {java.net.UnknownHostException: dione-mongoar.localdomain}}, {address=pandora-mongo.localdomain:27017, type=UNKNOWN, state=CONNECTING, exception={com.mongodb.MongoSocketException: pandora-mongo.localdomain}, caused by {java.net.UnknownHostException: pandora-mongo.localdomain}}, {address=riverside-mongo.localdomain:27017, type=UNKNOWN, state=CONNECTING, exception={com.mongodb.MongoSocketException: riverside-mongo.localdomain}, caused by {java.net.UnknownHostException: riverside-mongo.localdomain}}]

Nemám tušení, proč to funguje s jedním řidičem, ale žádný jiný.

Edit: Když se snažím připojit pouze k primárnímu uzlu s tímto url mongodb://login:pwd@host:27019/databaseto funguje, to nedokáže jen tehdy, když přidám ten druhý.

Položena 09/06/2015 v 12:44
zdroj uživatelem
V jiných jazycích...                            

Cookies help us deliver our services. By using our services, you agree to our use of cookies. Learn more