문제

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

도움이 되었습니까?

해결책

do you mean to use

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

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

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top