I am facing a problem in running Mongo Java Sharding Example. What i have done so far is:
1. Download a zip folder from github. 2. Create a new project in netbeans and add all the required files from zipped folder to the new project. 3. Run following servers: configd, mongos, shard1 and shard2 ...through following commands
Could you provide more information what commands exactly you tried to run that caused these error messages? Was it one of the official tutorials on the MongoDB website? Perhaps you could give a link or some code, that would help find the cause for the errors.
Also, which version of MongoDB and the Java driver are you using?
On Monday, September 3, 2012 3:15:12 PM UTC+10, Rahat Masood wrote:
> Hello Everyone,
> I am facing a problem in running Mongo Java Sharding Example. What i have > done so far is:
> 1. Download a zip folder from github. > 2. Create a new project in netbeans and add all the required files from > zipped folder to the new project. > 3. Run following servers: configd, mongos, shard1 and shard2 ...through > following commands
Just to add to my previous reply: Are you by any chance connecting to a mongod instead of the mongos? You need to make sure that you connect to mongos (in your example on port 30000) and then issue the addshard commands. mongod doesn't know about shards. Connecting to a mongod instead would result in exactly the error you experienced.
So if you use the javascript shell, you would have to call mongo with the --port 30000 parameter.
On Monday, September 3, 2012 3:15:12 PM UTC+10, Rahat Masood wrote:
> Hello Everyone,
> I am facing a problem in running Mongo Java Sharding Example. What i have > done so far is:
> 1. Download a zip folder from github. > 2. Create a new project in netbeans and add all the required files from > zipped folder to the new project. > 3. Run following servers: configd, mongos, shard1 and shard2 ...through > following commands
Thanks for the reply. Yes, you pointed out the exact problem. I was giving
mongod parameters instead of mongos. Now the problem is resolved, however,
now i am facing another problem in using the ports......
private static final int [] _shardPorts = { 10049, 10057 };
When I run 2 shards with the ports 10049 and 10057 and then tun mongo java
sharding example in netbeans, it gives an error:
I know this error is because these ports are already in use of sharding. To
remove this error, what i am doing is that whenever i compile the code I
give new port number.s
I want to know, is there any way to reconfigure the same ports because i am
running this example for my testing and giving new ports each time is not
feasible for me.
Regards,
Rahat Masood.
On Mon, Sep 3, 2012 at 11:10 AM, thomasr <thomas.ruecksti...@10gen.com>wrote:
> Just to add to my previous reply: Are you by any chance connecting to a
> mongod instead of the mongos?
> You need to make sure that you connect to mongos (in your example on port
> 30000) and then issue the
> addshard commands. mongod doesn't know about shards. Connecting to a
> mongod instead would result
> in exactly the error you experienced.
> So if you use the javascript shell, you would have to call mongo with the
> --port 30000 parameter.
> Best regards,
> Thomas
> On Monday, September 3, 2012 3:15:12 PM UTC+10, Rahat Masood wrote:
>> Hello Everyone,
>> I am facing a problem in running Mongo Java Sharding Example. What i have
>> done so far is:
>> 1. Download a zip folder from github.
>> 2. Create a new project in netbeans and add all the required files from
>> zipped folder to the new project.
>> 3. Run following servers: configd, mongos, shard1 and shard2 ...through
>> following commands
>> Can anyone please help in finding the exact problem????
>> Your efforts will be highly appreciated.
>> Regards,
>> Rahat Masood.
> --
> You received this message because you are subscribed to the Google
> Groups "mongodb-user" group.
> To post to this group, send email to mongodb-user@googlegroups.com
> To unsubscribe from this group, send email to
> mongodb-user+unsubscribe@googlegroups.com
> See also the IRC channel -- freenode.net#mongodb
It seems like you're trying to add the same shards to the mongos server that have already been added before. You only need to do this step once during the lifetime of the server, not every time you run the example. Try commenting out the lines that add the shards to the server and see if the code runs without errors.
On Monday, September 3, 2012 5:22:37 PM UTC+10, Rahat Masood wrote:
> Dear Thomas,
> Thanks for the reply. Yes, you pointed out the exact problem. I was giving > mongod parameters instead of mongos. Now the problem is resolved, however, > now i am facing another problem in using the ports......
> private static final int [] _shardPorts = { 10049, 10057 };
> When I run 2 shards with the ports 10049 and 10057 and then tun mongo java > sharding example in netbeans, it gives an error:
> I know this error is because these ports are already in use of sharding. > To remove this error, what i am doing is that whenever i compile the code I > give new port number.s
> I want to know, is there any way to reconfigure the same ports because i > am running this example for my testing and giving new ports each time is > not feasible for me.
> Regards, > Rahat Masood.
> On Mon, Sep 3, 2012 at 11:10 AM, thomasr <thomas.ru...@10gen.com<javascript:> > > wrote:
>> Hi Rahat,
>> Just to add to my previous reply: Are you by any chance connecting to a >> mongod instead of the mongos? >> You need to make sure that you connect to mongos (in your example on port >> 30000) and then issue the >> addshard commands. mongod doesn't know about shards. Connecting to a >> mongod instead would result >> in exactly the error you experienced.
>> So if you use the javascript shell, you would have to call mongo with the >> --port 30000 parameter.
>> Best regards, >> Thomas
>> On Monday, September 3, 2012 3:15:12 PM UTC+10, Rahat Masood wrote:
>>> Hello Everyone,
>>> I am facing a problem in running Mongo Java Sharding Example. What i >>> have done so far is:
>>> 1. Download a zip folder from github. >>> 2. Create a new project in netbeans and add all the required files from >>> zipped folder to the new project. >>> 3. Run following servers: configd, mongos, shard1 and shard2 ...through >>> following commands
>>> Can anyone please help in finding the exact problem????
>>> Your efforts will be highly appreciated.
>>> Regards, >>> Rahat Masood.
>> -- >> You received this message because you are subscribed to the Google >> Groups "mongodb-user" group. >> To post to this group, send email to mongod...@googlegroups.com<javascript:> >> To unsubscribe from this group, send email to >> mongodb-user...@googlegroups.com <javascript:> >> See also the IRC channel -- freenode.net#mongodb
Yes, i found the problem and sorted it out. Can u please tell, how can i
query the data stored on shards??
I think i need to connect to Mongos. I connected to it and then using
simple view query I printed out the statement. However, it is not working
because my dbcursor is empty.
Here is my code:
final Mongo mongo2 = new Mongo(new DBAddress("127.0.0.1", 30000,
"ExampleShardingData"));
db = mongo2.getDB("ExampleShardingData");
coll = db.getCollection("testShard");
BasicDBObject view1 = new BasicDBObject();
view1.put("x",20110114);
DBCursor cur = coll.find(view1);
Double id;
Binary b;
if (cur.hasNext()) {
DBObject o = cur.next();
id = (Double) (o.get("x"));
b = (Binary) (o.get("hash"));
System.out.println(id);
System.out.println(b);
}
DBCursor variable is not returning anything....Can you please find the
problem??
Do i need to query through CommnadResult because we are connecting now with
Mongos....
Regards,
Rahat Masood.
On Mon, Sep 3, 2012 at 12:38 PM, thomasr <thomas.ruecksti...@10gen.com>wrote:
> It seems like you're trying to add the same shards to the mongos server
> that have already been added before. You only need to do this step once
> during the lifetime of the server, not every time you run the example. Try
> commenting out the lines that add the shards to the server and see if the
> code runs without errors.
> Best regards,
> Thomas
> On Monday, September 3, 2012 5:22:37 PM UTC+10, Rahat Masood wrote:
>> Dear Thomas,
>> Thanks for the reply. Yes, you pointed out the exact problem. I was
>> giving mongod parameters instead of mongos. Now the problem is resolved,
>> however, now i am facing another problem in using the ports......
>> private static final int [] _shardPorts = { 10049, 10057 };
>> When I run 2 shards with the ports 10049 and 10057 and then tun mongo
>> java sharding example in netbeans, it gives an error:
>> I know this error is because these ports are already in use of sharding.
>> To remove this error, what i am doing is that whenever i compile the code I
>> give new port number.s
>> I want to know, is there any way to reconfigure the same ports because i
>> am running this example for my testing and giving new ports each time is
>> not feasible for me.
>> Regards,
>> Rahat Masood.
>> On Mon, Sep 3, 2012 at 11:10 AM, thomasr <thomas.ru...@10gen.com> wrote:
>>> Hi Rahat,
>>> Just to add to my previous reply: Are you by any chance connecting to a
>>> mongod instead of the mongos?
>>> You need to make sure that you connect to mongos (in your example on
>>> port 30000) and then issue the
>>> addshard commands. mongod doesn't know about shards. Connecting to a
>>> mongod instead would result
>>> in exactly the error you experienced.
>>> So if you use the javascript shell, you would have to call mongo with
>>> the --port 30000 parameter.
>>> Best regards,
>>> Thomas
>>> On Monday, September 3, 2012 3:15:12 PM UTC+10, Rahat Masood wrote:
>>>> Hello Everyone,
>>>> I am facing a problem in running Mongo Java Sharding Example. What i
>>>> have done so far is:
>>>> 1. Download a zip folder from github.
>>>> 2. Create a new project in netbeans and add all the required files from
>>>> zipped folder to the new project.
>>>> 3. Run following servers: configd, mongos, shard1 and shard2 ...through
>>>> following commands
>>>> Can anyone please help in finding the exact problem????
>>>> Your efforts will be highly appreciated.
>>>> Regards,
>>>> Rahat Masood.
>>> --
>>> You received this message because you are subscribed to the Google
>>> Groups "mongodb-user" group.
>>> To post to this group, send email to mongod...@googlegroups.com
>>> To unsubscribe from this group, send email to
>>> mongodb-user...@**googlegroups.com
>>> See also the IRC channel -- freenode.net#mongodb
>> --
> You received this message because you are subscribed to the Google
> Groups "mongodb-user" group.
> To post to this group, send email to mongodb-user@googlegroups.com
> To unsubscribe from this group, send email to
> mongodb-user+unsubscribe@googlegroups.com
> See also the IRC channel -- freenode.net#mongodb
I've looked through your code example, but unfortunately can't see any obvious reasons why you wouldn't be able to retrieve any data.
In order to diagnose your problem, could you try the following:
1. Could you connect to the mongos through the shell directly (mongo --port 30000) and try to access the document there? Are you able to retrieve it? 2. In your Java code, can you connect to the shard directly that contains the document, instead of the mongos? Are you able to retrieve it?
the answers to these questions will be very helpful in finding out why your code doesn't work.
Lastly, I'd like to refer you to the Java tutorials on the MongoDB website, in case you haven't seen them yet: http://www.mongodb.org/display/DOCS/Java+Tutorial They provide you with some more examples on how to connect to MongoDB through the Java driver.
On Tuesday, September 4, 2012 3:19:28 PM UTC+10, Rahat Masood wrote:
> Yes, i found the problem and sorted it out. Can u please tell, how can i > query the data stored on shards??
> I think i need to connect to Mongos. I connected to it and then using > simple view query I printed out the statement. However, it is not working > because my dbcursor is empty.
> Here is my code:
> final Mongo mongo2 = new Mongo(new DBAddress("127.0.0.1", 30000, > "ExampleShardingData"));
> db = mongo2.getDB("ExampleShardingData"); > coll = db.getCollection("testShard");
> BasicDBObject view1 = new BasicDBObject();
> view1.put("x",20110114); > DBCursor cur = coll.find(view1);
> Double id; > Binary b; > if (cur.hasNext()) { > DBObject o = cur.next();
> DBCursor variable is not returning anything....Can you please find the > problem??
> Do i need to query through CommnadResult because we are connecting now > with Mongos....
> Regards, > Rahat Masood.
> On Mon, Sep 3, 2012 at 12:38 PM, thomasr <thomas.ru...@10gen.com<javascript:> > > wrote:
>> Hi Rahat,
>> It seems like you're trying to add the same shards to the mongos server >> that have already been added before. You only need to do this step once >> during the lifetime of the server, not every time you run the example. Try >> commenting out the lines that add the shards to the server and see if the >> code runs without errors.
>> Best regards, >> Thomas
>> On Monday, September 3, 2012 5:22:37 PM UTC+10, Rahat Masood wrote:
>>> Dear Thomas,
>>> Thanks for the reply. Yes, you pointed out the exact problem. I was >>> giving mongod parameters instead of mongos. Now the problem is resolved, >>> however, now i am facing another problem in using the ports......
>>> private static final int [] _shardPorts = { 10049, 10057 };
>>> When I run 2 shards with the ports 10049 and 10057 and then tun mongo >>> java sharding example in netbeans, it gives an error:
>>> I know this error is because these ports are already in use of sharding. >>> To remove this error, what i am doing is that whenever i compile the code I >>> give new port number.s
>>> I want to know, is there any way to reconfigure the same ports because i >>> am running this example for my testing and giving new ports each time is >>> not feasible for me.
>>> Regards, >>> Rahat Masood.
>>> On Mon, Sep 3, 2012 at 11:10 AM, thomasr <thomas.ru...@10gen.com>wrote:
>>>> Hi Rahat,
>>>> Just to add to my previous reply: Are you by any chance connecting to a >>>> mongod instead of the mongos? >>>> You need to make sure that you connect to mongos (in your example on >>>> port 30000) and then issue the >>>> addshard commands. mongod doesn't know about shards. Connecting to a >>>> mongod instead would result >>>> in exactly the error you experienced.
>>>> So if you use the javascript shell, you would have to call mongo with >>>> the --port 30000 parameter.
>>>> Best regards, >>>> Thomas
>>>> On Monday, September 3, 2012 3:15:12 PM UTC+10, Rahat Masood wrote:
>>>>> Hello Everyone,
>>>>> I am facing a problem in running Mongo Java Sharding Example. What i >>>>> have done so far is:
>>>>> 1. Download a zip folder from github. >>>>> 2. Create a new project in netbeans and add all the required files >>>>> from zipped folder to the new project. >>>>> 3. Run following servers: configd, mongos, shard1 and shard2 >>>>> ...through following commands
>>>>> Can anyone please help in finding the exact problem????
>>>>> Your efforts will be highly appreciated.
>>>>> Regards, >>>>> Rahat Masood.
>>>> -- >>>> You received this message because you are subscribed to the Google >>>> Groups "mongodb-user" group. >>>> To post to this group, send email to mongod...@googlegroups.com
>>>> To unsubscribe from this group, send email to >>>> mongodb-user...@**googlegroups.com
>>>> See also the IRC channel -- freenode.net#mongodb
>>> -- >> You received this message because you are subscribed to the Google >> Groups "mongodb-user" group. >> To post to this group, send email to mongod...@googlegroups.com<javascript:> >> To unsubscribe from this group, send email to >> mongodb-user...@googlegroups.com <javascript:> >> See also the IRC channel -- freenode.net#mongodb
static DBCollection coll,coll2,coll3;
static DB db;
private static void insert1() throws Exception {
final Mongo mongo2 = new Mongo(new DBAddress("127.0.0.1", 30000,
"ExampleShardingData"));
db = mongo2.getDB("ExampleShardingD
ata");
coll = db.getCollection("testShard");
BasicDBObject view1 = new BasicDBObject();
view1.put("x",20110114);
DBCursor cur = coll.find(view1);
Double id;
Binary b;
if (cur.hasNext()) {
DBObject o = cur.next();
id = (Double) (o.get("x"));
b = (Binary) (o.get("hash"));
System.out.println(id);
System.out.println(b);
}
}
public ShardingTest() {
}
private static final int [] _shardPorts = { 10049, 10057 };
@Before
public static void setupCluster() throws Exception {
// Connect to mongos
final Mongo mongo = new Mongo(new DBAddress("127.0.0.1", 30000,
"admin"));
// Add the shards
/* for (final int shardPort : _shardPorts) {
final CommandResult result
= mongo.getDB("admin").command(new BasicDBObject("addshard",
("localhost:" + shardPort)));
System.out.println(result);
}
// Sleep for a bit to wait for all the nodes to be intialized.
Thread.sleep(5000);
// Enable sharding on a collection.
CommandResult result
= mongo.getDB("admin").command(new BasicDBObject("enablesharding",
"ExampleShardingData"));
System.out.println(result);*/
final BasicDBObject shardKey = new BasicDBObject("x", 1);
shardKey.put("hash", 1);
final BasicDBObject cmd = new BasicDBObject("shardcollection",
"ExampleShardingData.testShard");
yes i have Java Tutorials and also implemented them. They ware running
accurately. What i want is to make shards through java driver and then
query the data in those shards.
Regards,
Rahat Masood.
On Tue, Sep 4, 2012 at 10:56 AM, thomasr <thomas.ruecksti...@10gen.com>wrote:
> I've looked through your code example, but unfortunately can't see any
> obvious reasons why you wouldn't be able to retrieve any data.
> In order to diagnose your problem, could you try the following:
> 1. Could you connect to the mongos through the shell directly (mongo
> --port 30000) and try to access the document there? Are you able to
> retrieve it?
> 2. In your Java code, can you connect to the shard directly that
> contains the document, instead of the mongos? Are you able to retrieve it?
> the answers to these questions will be very helpful in finding out why
> your code doesn't work.
> Lastly, I'd like to refer you to the Java tutorials on the MongoDB
> website, in case you haven't seen them yet:
> http://www.mongodb.org/display/DOCS/Java+Tutorial > They provide you with some more examples on how to connect to MongoDB
> through the Java driver.
> Best regards,
> Thomas
> On Tuesday, September 4, 2012 3:19:28 PM UTC+10, Rahat Masood wrote:
>> Yes, i found the problem and sorted it out. Can u please tell, how can i
>> query the data stored on shards??
>> I think i need to connect to Mongos. I connected to it and then using
>> simple view query I printed out the statement. However, it is not working
>> because my dbcursor is empty.
>> Here is my code:
>> final Mongo mongo2 = new Mongo(new DBAddress("127.0.0.1", 30000,
>> "ExampleShardingData"));
>> db = mongo2.getDB("**ExampleShardingData");
>> coll = db.getCollection("testShard");
>> BasicDBObject view1 = new BasicDBObject();
>> view1.put("x",20110114);
>> DBCursor cur = coll.find(view1);
>> Double id;
>> Binary b;
>> if (cur.hasNext()) {
>> DBObject o = cur.next();
>> DBCursor variable is not returning anything....Can you please find the
>> problem??
>> Do i need to query through CommnadResult because we are connecting now
>> with Mongos....
>> Regards,
>> Rahat Masood.
>> On Mon, Sep 3, 2012 at 12:38 PM, thomasr <thomas.ru...@10gen.com> wrote:
>>> Hi Rahat,
>>> It seems like you're trying to add the same shards to the mongos server
>>> that have already been added before. You only need to do this step once
>>> during the lifetime of the server, not every time you run the example. Try
>>> commenting out the lines that add the shards to the server and see if the
>>> code runs without errors.
>>> Best regards,
>>> Thomas
>>> On Monday, September 3, 2012 5:22:37 PM UTC+10, Rahat Masood wrote:
>>>> Dear Thomas,
>>>> Thanks for the reply. Yes, you pointed out the exact problem. I was
>>>> giving mongod parameters instead of mongos. Now the problem is resolved,
>>>> however, now i am facing another problem in using the ports......
>>>> private static final int [] _shardPorts = { 10049, 10057 };
>>>> When I run 2 shards with the ports 10049 and 10057 and then tun mongo
>>>> java sharding example in netbeans, it gives an error:
>>>> I know this error is because these ports are already in use of
>>>> sharding. To remove this error, what i am doing is that whenever i compile
>>>> the code I give new port number.s
>>>> I want to know, is there any way to reconfigure the same ports because
>>>> i am running this example for my testing and giving new ports each time is
>>>> not feasible for me.
>>>> Regards,
>>>> Rahat Masood.
>>>> On Mon, Sep 3, 2012 at 11:10 AM, thomasr <thomas.ru...@10gen.com>wrote:
>>>>> Hi Rahat,
>>>>> Just to add to my previous reply: Are you by any chance connecting to
>>>>> a mongod instead of the mongos?
>>>>> You need to make sure that you connect to mongos (in your example on
>>>>> port 30000) and then issue the
were you able to solve your problem? I think what could have happened here is that you inserted documents directly to the mongod rather than through mongos. That would explain why you can't get any data back from mongos. I suggest you start your example code from scratch, and make sure that you always connect to mongos (port 30000), even for inserting the documents. Then you should be able to revtrieve them, both in the shell and through the Java driver.
Please let us know if you need any further assistance with this.
> yes i have Java Tutorials and also implemented them. They ware running > accurately. What i want is to make shards through java driver and then > query the data in those shards.
> Regards, > Rahat Masood.
> On Tue, Sep 4, 2012 at 10:56 AM, thomasr <thomas.ru...@10gen.com<javascript:> > > wrote:
>> Hi Rahat,
>> I've looked through your code example, but unfortunately can't see any >> obvious reasons why you wouldn't be able to retrieve any data.
>> In order to diagnose your problem, could you try the following:
>> 1. Could you connect to the mongos through the shell directly (mongo >> --port 30000) and try to access the document there? Are you able to >> retrieve it? >> 2. In your Java code, can you connect to the shard directly that >> contains the document, instead of the mongos? Are you able to retrieve it?
>> the answers to these questions will be very helpful in finding out why >> your code doesn't work.
>> Lastly, I'd like to refer you to the Java tutorials on the MongoDB >> website, in case you haven't seen them yet: >> http://www.mongodb.org/display/DOCS/Java+Tutorial >> They provide you with some more examples on how to connect to MongoDB >> through the Java driver.
>> Best regards, >> Thomas
>> On Tuesday, September 4, 2012 3:19:28 PM UTC+10, Rahat Masood wrote:
>>> Yes, i found the problem and sorted it out. Can u please tell, how can i >>> query the data stored on shards??
>>> I think i need to connect to Mongos. I connected to it and then using >>> simple view query I printed out the statement. However, it is not working >>> because my dbcursor is empty.
>>> Here is my code:
>>> final Mongo mongo2 = new Mongo(new DBAddress("127.0.0.1", 30000, >>> "ExampleShardingData"));
>>> db = mongo2.getDB("**ExampleShardingData"); >>> coll = db.getCollection("testShard");
>>> BasicDBObject view1 = new BasicDBObject();
>>> view1.put("x",20110114); >>> DBCursor cur = coll.find(view1);
>>> Double id; >>> Binary b; >>> if (cur.hasNext()) { >>> DBObject o = cur.next();
>>> DBCursor variable is not returning anything....Can you please find the >>> problem??
>>> Do i need to query through CommnadResult because we are connecting now >>> with Mongos....
>>> Regards, >>> Rahat Masood.
>>> On Mon, Sep 3, 2012 at 12:38 PM, thomasr <thomas.ru...@10gen.com> wrote:
>>>> Hi Rahat,
>>>> It seems like you're trying to add the same shards to the mongos server >>>> that have already been added before. You only need to do this step once >>>> during the lifetime of the server, not every time you run the example. Try >>>> commenting out the lines that add the shards to the server and see if the >>>> code runs without errors.
>>>> Best regards, >>>> Thomas
>>>> On Monday, September 3, 2012 5:22:37 PM UTC+10, Rahat Masood wrote:
>>>>> Dear Thomas,
>>>>> Thanks for the reply. Yes, you pointed out the exact problem. I was >>>>> giving mongod parameters instead of mongos. Now the problem is resolved, >>>>> however, now i am facing