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

Cannot read BSON symbol from MongoCollection<BasicDBObject> document

    • Type: Icon: Bug Bug
    • Resolution: Done
    • Priority: Icon: Minor - P4 Minor - P4
    • 3.0.4, 3.1.0
    • Affects Version/s: 3.0.3
    • Component/s: BSON
    • None
    • Environment:
      MongoDB server 3.0.4

      What I tried to do is to run a code from the documentation 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.

      Unable to find source-code formatter for language: text. Available languages are: actionscript, ada, applescript, bash, c, c#, c++, cpp, css, erlang, go, groovy, haskell, html, java, javascript, js, json, lua, none, nyan, objc, perl, php, python, r, rainbow, ruby, scala, sh, sql, swift, visualbasic, xml, yaml
      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
      

            Assignee:
            ross@mongodb.com Ross Lawley
            Reporter:
            alaz Alexander Azarov
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

              Created:
              Updated:
              Resolved: