I have a question regarding indexing in MongoDB. (I use the mongo-java-driver)
If the database contains many objects all of them have exact the same structure and the only differences are lets say, the value of some ID field and a name. Will indexing the ID field in the collection speed up the query after some certain object on the ID field?
I use MongoHQ "Cloud" MongoDB, maybe I am doing something wrong but indexing in this case wont get any better performance.
Thanks for your time.
/* just for testing */
DBCollection table = db.getCollection("user");
table.createIndex(new BasicDBObject("uuid", 1));
....
/* write */
for (int i = 0; i < numberOfInserts; i++) {
BasicDBObject document = new BasicDBObject();
document.put("name", "hello");
document.put("uuid", randomUUID.toString() + i);
table.insert(document);
}
....
/* read */
for (int i = 0; i < numberOfInserts; i++) {
whereQuery.put("uuid", randomUUID.toString() + i);
DBObject findOne = table.findOne(whereQuery);
}