Pregunta

I have the following...

DBCollection dbc = test.getCollection();
double count = dbc.count();
DBCursor cursor = dbc.find();
StringBuilder sb = new StringBuilder();
if( cursor.hasNext() )
  sb.append(cursor.next().toString());

This outputs only one record but shows a count of 2. This one seems to work...

DBCollection dbc = test.getCollection();
double count = dbc.count();
DBCursor cursor = dbc.find();
StringBuilder sb = new StringBuilder();
for(double i = 0.0; i<count; i++)
  sb.append(cursor.next().toString());

What am I missing

¿Fue útil?

Solución

do you mean to use

while( cursor.hasNext() )
    sb.append(cursor.next().toString());

Right now, you use 'if' but you probably want 'while'.

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top