Reputation: 332
I have a sharded cluster named test2.
db.collection.getShardDistribution() gives me this:
Why does my .count()
query only return total docs in shard0000 and my iterable only iterates through the documents in shard0000? What do I have to do to make my query return the entire collection?
System.out.println("Total docs: "+db.getCollection(collectionName).count());
FindIterable<Document> iterable = db.getCollection(collectionName).find();
Any query I perform with different parameters only iterates through shard0000.
Edit Connection string:
MongoClient mongoClient = new MongoClient("129.241.xxx.xx",27017);
This is the error. Should be port 27023. Thanks!
Upvotes: 1
Views: 377
Reputation: 332
The problem was that I was connecting to the wrong port after the database was sharded. I had to modify my connection string to use the correct port where my mongo instance was running.
This was my connection string.
MongoClient mongoClient = new MongoClient("129.241.xxx.xx",27017);
Changed the port to
MongoClient mongoClient = new MongoClient("129.241.xxx.xx",27023);
...and it worked. Thanks to @Markus W Mahlberg for pointing me in the right direction.
Upvotes: 2