java - Android MongoDB Document iteration not consistent, confused -


i'm trying iterate through documents , parse values , add them own lists. thing when try parse , add list stops half way through exact. when don't add code parse , add list prints out of them (4).

try {                     while(cursor.hasnext()) {                         system.out.println("cursor test" + cursor.next().tojson());                          mydoc = cursor.next();                         try {                             jsonobject object = new jsonobject(mydoc.tojson());                             username.add((string) object.get("name"));                             userid.add((string) object.get("id"));                             profilepic.add( (string) object.get("profilepic"));                               //system.out.println("userid:" + userid);                             //system.out.println("profilepic:" + profilepic);                             //system.out.println("username:" + username);                             //system.out.println("count: " + collectioncount);                         } catch (jsonexception e) {                             e.printstacktrace();                         }                     }                 } finally{cursor.close();} 

print out two

while

try {                     while(cursor.hasnext()) {                         system.out.println("cursor test" + cursor.next().tojson());                  } finally{cursor.close();} 

prints out expected

the first example calls cursor.next() twice, advancing cursor twice per loop. try calling once, below:

try {   while(cursor.hasnext()) {     mydoc = cursor.next();     system.out.println("cursor test" + mydoc.tojson());     try {       jsonobject object = new jsonobject(mydoc.tojson());       username.add((string) object.get("name"));       userid.add((string) object.get("id"));       profilepic.add( (string) object.get("profilepic"));     } catch (jsonexception e) {       e.printstacktrace();     }   } } finally{cursor.close();} 

Comments

Popular posts from this blog

javascript - Bootstrap Popover: iOS Safari strange behaviour -

Magento/PHP - Get phones on all members in a customer group -

session - Logging Out Using PHP -