If I do the following
DBCursor curs = db.getCollection("Person").find(query);
while (curs.hasNext())
{
...
}
where query is "{ "firstName" : { "$eq" : "Daffy"}}
then I get
com.mongodb.MongoInternalException: couldn't get next element
at com.mongodb.DBCursor.hasNext(DBCursor.java:459)
Yes, I (now) know the query object represents invalid BSON (but then someone who is learning this API wouldn't know that, since "$eq" seems logical when you have "$ne", "$gt" etc).
The fact remains though that there is nothing in the API for Cursor.hasNext() (or java.util.Iterator.hasNext() too which is cleaimed to be implemented here) that permits such an exception. Invalid BSON should be detected in "DBCollection.find()" IMHO, so the user doesn't get unexpected exceptions thrown