Random Key Select From MongoDB

Thursday, July 10, 2014

I am trying to insert a large set of data into MongoDb and retrieve random keys values from the collection. It takes about 29mins inserting about 2GB of data and several hours retrieving the key value pairs. This is very slow compared to other NoSQL datastore. What might possibly be the bottleneck.


INSERTING



while ((strLine = br.readLine()) != null) {
documentDetail.clear();
//String strLines = strLine.replaceAll("[-+.^:,]","");
tokens = strLine.split("\t");

documentDetail.put("key", tokens[0]);
documentDetail.put("value", tokens[1]);
start = System.currentTimeMillis();
collection.insert(documentDetail);
elapsed = System.currentTimeMillis()-start;
totalElapsed += elapsed;
}


SELECTING



while ((strLin = br.readLine()) != null) {
BasicDBObject query = new BasicDBObject();
query.put("name", strLin);

System.out.println(strLin);
start = System.currentTimeMillis();

DBCursor cursorDoc = collection.find(query, find);
while (cursorDoc.hasNext()) {
System.out.println(cursorDoc.next());
}
elapsed = System.currentTimeMillis()-start;
totalElapsed += elapsed;
System.out.println("Reading Ends...");
//field.clear();
}






http://ift.tt/1qZPybd