Uploaded image for project: 'Java Driver'
  1. Java Driver
  2. JAVA-1012

MongoException thrown for any document that has key named 'err'

    • Type: Icon: Bug Bug
    • Resolution: Duplicate
    • Priority: Icon: Major - P3 Major - P3
    • None
    • Affects Version/s: 2.11.3
    • Component/s: None
    • Labels:
      None

      I've found a bug in the mongo java driver (v.2.11.3).

      Any document containing a key 'err' or 'errmsg' will throw a MongoException when retrieved using findOne().

      com.mongodb.MongoException: POSTAL_CODE_NOT_FOUND
      at com.mongodb.MongoException.parse(MongoException.java:82)
      at com.mongodb.DBApiLayer$MyCollection.__find(DBApiLayer.java:292)
      at com.mongodb.DBApiLayer$MyCollection.__find(DBApiLayer.java:273)
      at com.mongodb.DBCollection.findOne(DBCollection.java:347)
      at com.mongodb.DBCollection.findOne(DBCollection.java:332)

      I traced the problem to com.mongodb.ServerError.

      public class ServerError {

      ServerError( DBObject o )

      { _err = getMsg( o , null ); if ( _err == null ) throw new IllegalArgumentException( "need to have $err" ); _code = getCode( o ); }

      static String getMsg( BSONObject o , String def )

      { Object e = o.get( "$err" ); if ( e == null ) e = o.get( "err" ); if ( e == null ) e = o.get( "errmsg" ); if ( e == null ) return def; return e.toString(); }

      Not sure why it would try to interpret an application level 'err' message as a reason to throw a MongoException:

            Assignee:
            Unassigned Unassigned
            Reporter:
            carl@researchforgood.com Carl Sayres
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: