Skip to content

Instantly share code, notes, and snippets.

Created January 14, 2015 03:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save anonymous/8b6783ab067f04e483d6 to your computer and use it in GitHub Desktop.
Save anonymous/8b6783ab067f04e483d6 to your computer and use it in GitHub Desktop.
import com.mongodb.BasicDBObject;
import com.mongodb.DB;
import com.mongodb.DBCollection;
import com.mongodb.MongoClient;
import com.mongodb.MongoClientURI;
import java.net.UnknownHostException;
import java.util.Random;
public class ShardingConfusion {
public static void main(String[] args) throws UnknownHostException {
MongoClient client = new MongoClient(new MongoClientURI("mongodb://localhost,localhost:27018"));
Random random = new Random();
while (true) {
DB db = client.getDB("Java-driver-test");
DBCollection c = db.getCollection("DBCursorTest" + random.nextLong());
for (int i = 0; i < 100; i++) {
c.insert(new BasicDBObject("_id", i));
}
long count = c.count();
if (count != 100) {
System.out.println("Uh oh: count is " + count + " on collection " + c.getFullName());
} else {
System.out.println("All is well");
db.dropDatabase();
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment