org.bson.BsonInvalidOperationException: readString can only be called when CurrentBSONType is STRING, not when CurrentBSONType is SYMBOL.

JIRA | Alexander Azarov | 2 years ago
tip
Do you know that we can give you better hits? Get more relevant results from Samebug’s stack trace search.
  1. 0

    What I tried to do is to run a code from [the documentation|http://mongodb.github.io/mongo-java-driver/3.0/driver/reference/crud/#codecregistry] to use {{BasicDBObject}} in the new CRUD API. My test document contained a BSON symbol and I got an exception where I didn't expect to have one. {code:text} scala> import com.mongodb._ import com.mongodb._ scala> val db = new MongoClient("localhost").getDatabase("test") июл 31, 2015 7:59:31 PM com.mongodb.diagnostics.logging.JULLogger log INFO: Cluster created with settings {hosts=[localhost:27017], mode=SINGLE, requiredClusterType=UNKNOWN, serverSelectionTimeout='30000 ms', maxWaitQueueSize=500} db: com.mongodb.client.MongoDatabase = com.mongodb.MongoDatabaseImpl@2ff5be19 scala> июл 31, 2015 7:59:31 PM com.mongodb.diagnostics.logging.JULLogger log INFO: Opened connection [connectionId{localValue:1, serverValue:6}] to localhost:27017 июл 31, 2015 7:59:31 PM com.mongodb.diagnostics.logging.JULLogger log INFO: Monitor thread successfully connected to server with description ServerDescription{address=localhost:27017, type=STANDALONE, state=CONNECTED, ok=true, version=ServerVersion{versionList=[3, 0, 4]}, minWireVersion=0, maxWireVersion=3, electionId=null, maxDocumentSize=16777216, roundTripTimeNanos=560000} scala> scala> db.getCollection("test").find.first июл 31, 2015 7:59:52 PM com.mongodb.diagnostics.logging.JULLogger log INFO: Opened connection [connectionId{localValue:2, serverValue:7}] to localhost:27017 res0: org.bson.Document = Document{{_id=55bb50acb5b97f6d98b6186c, i32=1, s=str, sym=symbol}} scala> db.getCollection("test", classOf[BasicDBObject]).find.first org.bson.BsonInvalidOperationException: readString can only be called when CurrentBSONType is STRING, not when CurrentBSONType is SYMBOL. at org.bson.AbstractBsonReader.verifyBSONType(AbstractBsonReader.java:655) at org.bson.AbstractBsonReader.checkPreconditions(AbstractBsonReader.java:687) at org.bson.AbstractBsonReader.readString(AbstractBsonReader.java:428) at org.bson.codecs.StringCodec.decode(StringCodec.java:35) at org.bson.codecs.StringCodec.decode(StringCodec.java:27) at com.mongodb.DBObjectCodec.readValue(DBObjectCodec.java:306) at com.mongodb.DBObjectCodec.readDocument(DBObjectCodec.java:345) at com.mongodb.DBObjectCodec.decode(DBObjectCodec.java:136) at com.mongodb.DBObjectCodec.decode(DBObjectCodec.java:61) at com.mongodb.connection.ReplyMessage.<init>(ReplyMessage.java:57) at com.mongodb.connection.QueryProtocol.receiveMessage(QueryProtocol.java:290) at com.mongodb.connection.QueryProtocol.execute(QueryProtocol.java:229) at com.mongodb.connection.QueryProtocol.execute(QueryProtocol.java:38) at com.mongodb.connection.DefaultServer$DefaultServerProtocolExecutor.execute(DefaultServer.java:155) at com.mongodb.connection.DefaultServerConnection.executeProtocol(DefaultServerConnection.java:219) at com.mongodb.connection.DefaultServerConnection.query(DefaultServerConnection.java:166) at com.mongodb.operation.FindOperation$1.call(FindOperation.java:397) at com.mongodb.operation.FindOperation$1.call(FindOperation.java:394) at com.mongodb.operation.OperationHelper.withConnectionSource(OperationHelper.java:195) at com.mongodb.operation.OperationHelper.withConnection(OperationHelper.java:168) at com.mongodb.operation.FindOperation.execute(FindOperation.java:394) at com.mongodb.operation.FindOperation.execute(FindOperation.java:57) at com.mongodb.Mongo.execute(Mongo.java:738) at com.mongodb.Mongo$2.execute(Mongo.java:725) at com.mongodb.FindIterableImpl$FindOperationIterable.first(FindIterableImpl.java:197) at com.mongodb.FindIterableImpl.first(FindIterableImpl.java:140) ... 43 elided {code}

    JIRA | 2 years ago | Alexander Azarov
    org.bson.BsonInvalidOperationException: readString can only be called when CurrentBSONType is STRING, not when CurrentBSONType is SYMBOL.
  2. 0

    What I tried to do is to run a code from [the documentation|http://mongodb.github.io/mongo-java-driver/3.0/driver/reference/crud/#codecregistry] to use {{BasicDBObject}} in the new CRUD API. My test document contained a BSON symbol and I got an exception where I didn't expect to have one. {code:text} scala> import com.mongodb._ import com.mongodb._ scala> val db = new MongoClient("localhost").getDatabase("test") июл 31, 2015 7:59:31 PM com.mongodb.diagnostics.logging.JULLogger log INFO: Cluster created with settings {hosts=[localhost:27017], mode=SINGLE, requiredClusterType=UNKNOWN, serverSelectionTimeout='30000 ms', maxWaitQueueSize=500} db: com.mongodb.client.MongoDatabase = com.mongodb.MongoDatabaseImpl@2ff5be19 scala> июл 31, 2015 7:59:31 PM com.mongodb.diagnostics.logging.JULLogger log INFO: Opened connection [connectionId{localValue:1, serverValue:6}] to localhost:27017 июл 31, 2015 7:59:31 PM com.mongodb.diagnostics.logging.JULLogger log INFO: Monitor thread successfully connected to server with description ServerDescription{address=localhost:27017, type=STANDALONE, state=CONNECTED, ok=true, version=ServerVersion{versionList=[3, 0, 4]}, minWireVersion=0, maxWireVersion=3, electionId=null, maxDocumentSize=16777216, roundTripTimeNanos=560000} scala> scala> db.getCollection("test").find.first июл 31, 2015 7:59:52 PM com.mongodb.diagnostics.logging.JULLogger log INFO: Opened connection [connectionId{localValue:2, serverValue:7}] to localhost:27017 res0: org.bson.Document = Document{{_id=55bb50acb5b97f6d98b6186c, i32=1, s=str, sym=symbol}} scala> db.getCollection("test", classOf[BasicDBObject]).find.first org.bson.BsonInvalidOperationException: readString can only be called when CurrentBSONType is STRING, not when CurrentBSONType is SYMBOL. at org.bson.AbstractBsonReader.verifyBSONType(AbstractBsonReader.java:655) at org.bson.AbstractBsonReader.checkPreconditions(AbstractBsonReader.java:687) at org.bson.AbstractBsonReader.readString(AbstractBsonReader.java:428) at org.bson.codecs.StringCodec.decode(StringCodec.java:35) at org.bson.codecs.StringCodec.decode(StringCodec.java:27) at com.mongodb.DBObjectCodec.readValue(DBObjectCodec.java:306) at com.mongodb.DBObjectCodec.readDocument(DBObjectCodec.java:345) at com.mongodb.DBObjectCodec.decode(DBObjectCodec.java:136) at com.mongodb.DBObjectCodec.decode(DBObjectCodec.java:61) at com.mongodb.connection.ReplyMessage.<init>(ReplyMessage.java:57) at com.mongodb.connection.QueryProtocol.receiveMessage(QueryProtocol.java:290) at com.mongodb.connection.QueryProtocol.execute(QueryProtocol.java:229) at com.mongodb.connection.QueryProtocol.execute(QueryProtocol.java:38) at com.mongodb.connection.DefaultServer$DefaultServerProtocolExecutor.execute(DefaultServer.java:155) at com.mongodb.connection.DefaultServerConnection.executeProtocol(DefaultServerConnection.java:219) at com.mongodb.connection.DefaultServerConnection.query(DefaultServerConnection.java:166) at com.mongodb.operation.FindOperation$1.call(FindOperation.java:397) at com.mongodb.operation.FindOperation$1.call(FindOperation.java:394) at com.mongodb.operation.OperationHelper.withConnectionSource(OperationHelper.java:195) at com.mongodb.operation.OperationHelper.withConnection(OperationHelper.java:168) at com.mongodb.operation.FindOperation.execute(FindOperation.java:394) at com.mongodb.operation.FindOperation.execute(FindOperation.java:57) at com.mongodb.Mongo.execute(Mongo.java:738) at com.mongodb.Mongo$2.execute(Mongo.java:725) at com.mongodb.FindIterableImpl$FindOperationIterable.first(FindIterableImpl.java:197) at com.mongodb.FindIterableImpl.first(FindIterableImpl.java:140) ... 43 elided {code}

    JIRA | 2 years ago | Alexander Azarov
    org.bson.BsonInvalidOperationException: readString can only be called when CurrentBSONType is STRING, not when CurrentBSONType is SYMBOL.

    Root Cause Analysis

    1. org.bson.BsonInvalidOperationException

      readString can only be called when CurrentBSONType is STRING, not when CurrentBSONType is SYMBOL.

      at org.bson.AbstractBsonReader.verifyBSONType()
    2. MongoDB Java Driver
      FindIterableImpl.first
      1. org.bson.AbstractBsonReader.verifyBSONType(AbstractBsonReader.java:655)
      2. org.bson.AbstractBsonReader.checkPreconditions(AbstractBsonReader.java:687)
      3. org.bson.AbstractBsonReader.readString(AbstractBsonReader.java:428)
      4. org.bson.codecs.StringCodec.decode(StringCodec.java:35)
      5. org.bson.codecs.StringCodec.decode(StringCodec.java:27)
      6. com.mongodb.DBObjectCodec.readValue(DBObjectCodec.java:306)
      7. com.mongodb.DBObjectCodec.readDocument(DBObjectCodec.java:345)
      8. com.mongodb.DBObjectCodec.decode(DBObjectCodec.java:136)
      9. com.mongodb.DBObjectCodec.decode(DBObjectCodec.java:61)
      10. com.mongodb.connection.ReplyMessage.<init>(ReplyMessage.java:57)
      11. com.mongodb.connection.QueryProtocol.receiveMessage(QueryProtocol.java:290)
      12. com.mongodb.connection.QueryProtocol.execute(QueryProtocol.java:229)
      13. com.mongodb.connection.QueryProtocol.execute(QueryProtocol.java:38)
      14. com.mongodb.connection.DefaultServer$DefaultServerProtocolExecutor.execute(DefaultServer.java:155)
      15. com.mongodb.connection.DefaultServerConnection.executeProtocol(DefaultServerConnection.java:219)
      16. com.mongodb.connection.DefaultServerConnection.query(DefaultServerConnection.java:166)
      17. com.mongodb.operation.FindOperation$1.call(FindOperation.java:397)
      18. com.mongodb.operation.FindOperation$1.call(FindOperation.java:394)
      19. com.mongodb.operation.OperationHelper.withConnectionSource(OperationHelper.java:195)
      20. com.mongodb.operation.OperationHelper.withConnection(OperationHelper.java:168)
      21. com.mongodb.operation.FindOperation.execute(FindOperation.java:394)
      22. com.mongodb.operation.FindOperation.execute(FindOperation.java:57)
      23. com.mongodb.Mongo.execute(Mongo.java:738)
      24. com.mongodb.Mongo$2.execute(Mongo.java:725)
      25. com.mongodb.FindIterableImpl$FindOperationIterable.first(FindIterableImpl.java:197)
      26. com.mongodb.FindIterableImpl.first(FindIterableImpl.java:140)
      26 frames