Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.java.programmer > #27546 > unrolled thread
| Started by | Navneet Mathpal <navneetmathpal93@gmail.com> |
|---|---|
| First post | 2014-02-18 08:25 -0800 |
| Last post | 2014-02-18 15:13 -0800 |
| Articles | 3 — 3 participants |
Back to article view | Back to comp.lang.java.programmer
while loop is not working properly why Navneet Mathpal <navneetmathpal93@gmail.com> - 2014-02-18 08:25 -0800
Re: while loop is not working properly why Daniel Pitts <newsgroup.nospam@virtualinfinity.net> - 2014-02-18 10:02 -0800
Re: while loop is not working properly why Roedy Green <see_website@mindprod.com.invalid> - 2014-02-18 15:13 -0800
| From | Navneet Mathpal <navneetmathpal93@gmail.com> |
|---|---|
| Date | 2014-02-18 08:25 -0800 |
| Subject | while loop is not working properly why |
| Message-ID | <7e697752-e40a-42a1-b96d-3f37fc37dbed@googlegroups.com> |
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");
}
[toc] | [next] | [standalone]
| From | Daniel Pitts <newsgroup.nospam@virtualinfinity.net> |
|---|---|
| Date | 2014-02-18 10:02 -0800 |
| Message-ID | <dfNMu.319747$Z94.260283@fx26.iad> |
| In reply to | #27546 |
On 2/18/14 8:25 AM, Navneet Mathpal wrote:
>
>
>
> 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.
[toc] | [prev] | [next] | [standalone]
| From | Roedy Green <see_website@mindprod.com.invalid> |
|---|---|
| Date | 2014-02-18 15:13 -0800 |
| Message-ID | <75q7g95jsh9l373k4nurdnk39sf8u3sh0n@4ax.com> |
| In reply to | #27546 |
On Tue, 18 Feb 2014 08:25:41 -0800 (PST), Navneet Mathpal
<navneetmathpal93@gmail.com> wrote, quoted or indirectly quoted
someone who said :
>while (cursor.hasNext()) {
I suggest you add out.println( cursor.hasNext() );
just prior to the while.
--
Roedy Green Canadian Mind Products http://mindprod.com
The future has already happened, it just isn’t evenly distributed.
~ William Gibson (born: 1948-03-17 age: 65)
[toc] | [prev] | [standalone]
Back to top | Article view | comp.lang.java.programmer
csiph-web