Account Options

  1. Sign in
The old Google Groups will be going away soon, but your browser is incompatible with the new version.
Google Groups Home
« Groups Home
Message from discussion SlaveOk queries doesn't seems to go through mongoS
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
Simon T.  
View profile  
 More options Mar 29 2012, 3:27 pm
From: "Simon T." <simon.tou...@gmail.com>
Date: Thu, 29 Mar 2012 12:27:40 -0700 (PDT)
Local: Thurs, Mar 29 2012 3:27 pm
Subject: Re: [mongodb-user] Re: SlaveOk queries doesn't seems to go through mongoS

The problem is indeed persistent, I never could get the queries to be
redirected to the secondary while passing by the mongos.

The scripts are very simple: it is just looping queries. Here is two
examples that does the same thing, one in java and the other one in C#:

JAVA:
try {
Mongo _mongo = new Mongo("osmngs01", 27017);
_mongo.setReadPreference(ReadPreference.SECONDARY);
DB db = _mongo.getDB("AAAAA");
if (db.authenticate("XXXXXXX", "YYYYYYYY".toCharArray()) == false) {
String message = String.format("Initialization Error: Failed to
authenticate to %1$s.", "osmngs01");
System.out.println(message);

}

DBCollection coll = db.getCollection("players");
for(int i=0;i<10000;i++)
{
DBObject player = coll.findOne(new BasicDBObject("s_nintendoID",
Integer.toString(i)));

System.out.println("index: " + i + " players: " + player);

}
} catch (UnknownHostException ex) {

String message = String.format("Initialization Error: Host %1$s does not
exists. Message: %2$s",
"osmngs01", ex.getMessage());
System.out.println(message);
} catch (MongoException ex) {

String message = String.format("Initialization Error: Cannot connect to
host %1$s:%2$s. Message: %3$s",
"osmngs01", 27017, ex.getMessage());
System.out.println(message);

}

AND C#:

string connectionString = "mongodb://XXXXX:YYYYY@osmngs01/?slaveOk=true";
MongoServer mongoServer = MongoServer.Create(connectionString);
MongoDatabase mongoDB = mongoServer.GetDatabase(MONGO_DB);
MongoCollection<BsonDocument> documents = mongoDB.GetCollection("players");
Random rndNb = new Random();
for (int i = 0; i < 15000; i++)
{
int iPlayer = rndNb.Next(1, 400000);
try
{
var query = Query.EQ("s_nintendoID", iPlayer.ToString());

BsonDocument bsonPlayer = documents.FindOne(query);

}

catch (Exception exc)
{
System.Diagnostics.Debug.WriteLine(exc.Message);

}
}

Simon

 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.