while loop is not working properly why

N

Navneet Mathpal

cursor is not going inside the while why??


public void fetch_data() throws Exception
{
Mongo mongo = new Mongo("localhost", 27017);
DB db = mongo.getDB("relevancy_data");
DBCollection collection = db.getCollection("relevancy");

BasicDBObject andQuery = new BasicDBObject();
List<BasicDBObject> obj = new ArrayList<BasicDBObject>();
obj.add(new BasicDBObject("Platform","ElasticSearch"));
obj.add(new BasicDBObject("Enviroment", "Developer"));
obj.add(new BasicDBObject("Test_name", "Search_apple"));
andQuery.put("$and", obj);

System.out.println(obj.size());
//System.out.println(andQuery.toString());

DBCursor cursor = collection.find(andQuery);

while (cursor.hasNext()) {
System.out.println("inside of while");
System.out.println(cursor.next());
}
System.out.println("outside of while");


}
 
D

Daniel Pitts

cursor is not going inside the while why??


public void fetch_data() throws Exception
{
Mongo mongo = new Mongo("localhost", 27017);
DB db = mongo.getDB("relevancy_data");
DBCollection collection = db.getCollection("relevancy");

BasicDBObject andQuery = new BasicDBObject();
List<BasicDBObject> obj = new ArrayList<BasicDBObject>();
obj.add(new BasicDBObject("Platform","ElasticSearch"));
obj.add(new BasicDBObject("Enviroment", "Developer"));
obj.add(new BasicDBObject("Test_name", "Search_apple"));
andQuery.put("$and", obj);

System.out.println(obj.size());
//System.out.println(andQuery.toString());

DBCursor cursor = collection.find(andQuery);

while (cursor.hasNext()) {
System.out.println("inside of while");
System.out.println(cursor.next());
}
System.out.println("outside of while");


}

The while loop is working properly. My guess is that cursor.hasNext()
returns false.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,997
Messages
2,570,240
Members
46,830
Latest member
HeleneMull

Latest Threads

Top