com.mongodb.MongoException: BSONElement: bad type 101

JIRA | Jeff Yemin | 4 years ago
  1. 0

    Depending on where the null characters appear and how many of them there are, you get different errors. Here's one reproducible case using Java: {code} DBCollection c = m.getDB("test").getCollection("CS4355"); String s = URLDecoder.decode("/students?%2500%16%00%00%00%02hello%00%06%00%00%00world%00%00=%2500", "UTF-8"); DBObject obj = new BasicDBObject("embedded", new BasicDBObject(s, 1)); c.insert(obj, WriteConcern.SAFE); DBObject objOut = c.findOne(obj); System.out.println(objOut); {code} The insert returns normally, but the call to findOne throws an exception: {noformat} Exception in thread "main" com.mongodb.MongoException: BSONElement: bad type 101 at com.mongodb.MongoException.parse(MongoException.java:82) at com.mongodb.DBApiLayer$MyCollection.__find(DBApiLayer.java:293) at com.mongodb.DBApiLayer$MyCollection.__find(DBApiLayer.java:274) at com.mongodb.DBCollection.findOne(DBCollection.java:710) at com.mongodb.DBCollection.findOne(DBCollection.java:652) at CS4355.main(CS4355.java:39) {noformat} and validate fails as well: {noformat} Mon Sep 10 20:56:55 [conn2] runQuery called test.$cmd { validate: "CS4355", full: true } Mon Sep 10 20:56:55 [conn2] run command test.$cmd { validate: "CS4355", full: true } Mon Sep 10 20:56:55 [conn2] CMD: validate test.CS4355 Mon Sep 10 20:56:55 [conn2] Assertion: 13655:BSONElement: bad type 101 0x10007fd6c 0x1000082ad 0x1000162a1 0x10001632e 0x1004ab99f 0x1004adce6 0x10048c3a4 0x10048cd76 0x10045457b 0x10045600a 0x1003a6b61 0x1003a7b02 0x1005a678f 0x1001387ad 0x1005b2af9 0x7fff86d6d782 0x7fff86d5a1c1 0 mongod 0x000000010007fd6c _ZN5mongo11msgassertedEiPKc + 396 1 mongod 0x00000001000082ad _ZNK5mongo11BSONElement4sizeEi + 461 2 mongod 0x00000001000162a1 _ZNK5mongo7BSONObj5validEv + 177 3 mongod 0x000000010001632e _ZNK5mongo7BSONObj5validEv + 318 4 mongod 0x00000001004ab99f _ZN5mongo11ValidateCmd10validateNSEPKcPNS_16NamespaceDetailsERKNS_7BSONObjERNS_14BSONObjBuilderE + 6543 5 mongod 0x00000001004adce6 _ZN5mongo11ValidateCmd3runERKSsRNS_7BSONObjEiRSsRNS_14BSONObjBuilderEb + 518 6 mongod 0x000000010048c3a4 _ZN5mongo11execCommandEPNS_7CommandERNS_6ClientEiPKcRNS_7BSONObjERNS_14BSONObjBuilderEb + 2692 7 mongod 0x000000010048cd76 _ZN5mongo12_runCommandsEPKcRNS_7BSONObjERNS_11_BufBuilderINS_16TrivialAllocatorEEERNS_14BSONObjBuilderEbi + 694 8 mongod 0x000000010045457b _ZN5mongo11runCommandsEPKcRNS_7BSONObjERNS_5CurOpERNS_11_BufBuilderINS_16TrivialAllocatorEEERNS_14BSONObjBuilderEbi + 59 9 mongod 0x000000010045600a _ZN5mongo8runQueryERNS_7MessageERNS_12QueryMessageERNS_5CurOpES1_ + 5818 10 mongod 0x00000001003a6b61 _ZN5mongoL13receivedQueryERNS_6ClientERNS_10DbResponseERNS_7MessageE + 337 11 mongod 0x00000001003a7b02 _ZN5mongo16assembleResponseERNS_7MessageERNS_10DbResponseERKNS_11HostAndPortE + 1458 12 mongod 0x00000001005a678f _ZN5mongo16MyMessageHandler7processERNS_7MessageEPNS_21AbstractMessagingPortEPNS_9LastErrorE + 271 13 mongod 0x00000001001387ad _ZN5mongo3pms9threadRunEPNS_13MessagingPortE + 605 14 mongod 0x00000001005b2af9 thread_proxy + 137 15 libsystem_c.dylib 0x00007fff86d6d782 _pthread_start + 327 16 libsystem_c.dylib 0x00007fff86d5a1c1 thread_start + 13 Mon Sep 10 20:56:55 [conn2] Invalid bson detected in test.CS4355 with _id: ObjectId('504e8c4e57862e8db678a9a2') {noformat}

    JIRA | 4 years ago | Jeff Yemin
    com.mongodb.MongoException: BSONElement: bad type 101
  2. 0

    Depending on where the null characters appear and how many of them there are, you get different errors. Here's one reproducible case using Java: {code} DBCollection c = m.getDB("test").getCollection("CS4355"); String s = URLDecoder.decode("/students?%2500%16%00%00%00%02hello%00%06%00%00%00world%00%00=%2500", "UTF-8"); DBObject obj = new BasicDBObject("embedded", new BasicDBObject(s, 1)); c.insert(obj, WriteConcern.SAFE); DBObject objOut = c.findOne(obj); System.out.println(objOut); {code} The insert returns normally, but the call to findOne throws an exception: {noformat} Exception in thread "main" com.mongodb.MongoException: BSONElement: bad type 101 at com.mongodb.MongoException.parse(MongoException.java:82) at com.mongodb.DBApiLayer$MyCollection.__find(DBApiLayer.java:293) at com.mongodb.DBApiLayer$MyCollection.__find(DBApiLayer.java:274) at com.mongodb.DBCollection.findOne(DBCollection.java:710) at com.mongodb.DBCollection.findOne(DBCollection.java:652) at CS4355.main(CS4355.java:39) {noformat} and validate fails as well: {noformat} Mon Sep 10 20:56:55 [conn2] runQuery called test.$cmd { validate: "CS4355", full: true } Mon Sep 10 20:56:55 [conn2] run command test.$cmd { validate: "CS4355", full: true } Mon Sep 10 20:56:55 [conn2] CMD: validate test.CS4355 Mon Sep 10 20:56:55 [conn2] Assertion: 13655:BSONElement: bad type 101 0x10007fd6c 0x1000082ad 0x1000162a1 0x10001632e 0x1004ab99f 0x1004adce6 0x10048c3a4 0x10048cd76 0x10045457b 0x10045600a 0x1003a6b61 0x1003a7b02 0x1005a678f 0x1001387ad 0x1005b2af9 0x7fff86d6d782 0x7fff86d5a1c1 0 mongod 0x000000010007fd6c _ZN5mongo11msgassertedEiPKc + 396 1 mongod 0x00000001000082ad _ZNK5mongo11BSONElement4sizeEi + 461 2 mongod 0x00000001000162a1 _ZNK5mongo7BSONObj5validEv + 177 3 mongod 0x000000010001632e _ZNK5mongo7BSONObj5validEv + 318 4 mongod 0x00000001004ab99f _ZN5mongo11ValidateCmd10validateNSEPKcPNS_16NamespaceDetailsERKNS_7BSONObjERNS_14BSONObjBuilderE + 6543 5 mongod 0x00000001004adce6 _ZN5mongo11ValidateCmd3runERKSsRNS_7BSONObjEiRSsRNS_14BSONObjBuilderEb + 518 6 mongod 0x000000010048c3a4 _ZN5mongo11execCommandEPNS_7CommandERNS_6ClientEiPKcRNS_7BSONObjERNS_14BSONObjBuilderEb + 2692 7 mongod 0x000000010048cd76 _ZN5mongo12_runCommandsEPKcRNS_7BSONObjERNS_11_BufBuilderINS_16TrivialAllocatorEEERNS_14BSONObjBuilderEbi + 694 8 mongod 0x000000010045457b _ZN5mongo11runCommandsEPKcRNS_7BSONObjERNS_5CurOpERNS_11_BufBuilderINS_16TrivialAllocatorEEERNS_14BSONObjBuilderEbi + 59 9 mongod 0x000000010045600a _ZN5mongo8runQueryERNS_7MessageERNS_12QueryMessageERNS_5CurOpES1_ + 5818 10 mongod 0x00000001003a6b61 _ZN5mongoL13receivedQueryERNS_6ClientERNS_10DbResponseERNS_7MessageE + 337 11 mongod 0x00000001003a7b02 _ZN5mongo16assembleResponseERNS_7MessageERNS_10DbResponseERKNS_11HostAndPortE + 1458 12 mongod 0x00000001005a678f _ZN5mongo16MyMessageHandler7processERNS_7MessageEPNS_21AbstractMessagingPortEPNS_9LastErrorE + 271 13 mongod 0x00000001001387ad _ZN5mongo3pms9threadRunEPNS_13MessagingPortE + 605 14 mongod 0x00000001005b2af9 thread_proxy + 137 15 libsystem_c.dylib 0x00007fff86d6d782 _pthread_start + 327 16 libsystem_c.dylib 0x00007fff86d5a1c1 thread_start + 13 Mon Sep 10 20:56:55 [conn2] Invalid bson detected in test.CS4355 with _id: ObjectId('504e8c4e57862e8db678a9a2') {noformat}

    JIRA | 4 years ago | Jeff Yemin
    com.mongodb.MongoException: BSONElement: bad type 101
  3. 0

    Error using $elemMatch

    GitHub | 3 years ago | ubiquitousthey
    com.mongodb.MongoException: invalid parameter: expected an object ($elemMatch)
  4. Speed up your debug routine!

    Automated exception search integrated into your IDE

  5. 0

    Problem reading from primary using Java driver and TaggedReadPreference

    Google Groups | 5 years ago | Bryan Hunt
    com.mongodb.MongoException: Could not find any valid secondaries with the supplied tags ('{ "locale" : "sc"}'
  6. 0

    Does the Java Driver support $slice operator?

    Google Groups | 6 years ago | Stuart King
    com.mongodb.MongoException: invalid operator: $slice

    Not finding the right solution?
    Take a tour to get the most out of Samebug.

    Tired of useless tips?

    Automated exception search integrated into your IDE

    Root Cause Analysis

    1. com.mongodb.MongoException

      BSONElement: bad type 101

      at com.mongodb.MongoException.parse()
    2. MongoDB Java Driver
      DBCollection.findOne
      1. com.mongodb.MongoException.parse(MongoException.java:82)
      2. com.mongodb.DBApiLayer$MyCollection.__find(DBApiLayer.java:293)
      3. com.mongodb.DBApiLayer$MyCollection.__find(DBApiLayer.java:274)
      4. com.mongodb.DBCollection.findOne(DBCollection.java:710)
      5. com.mongodb.DBCollection.findOne(DBCollection.java:652)
      5 frames
    3. Unknown
      CS4355.main
      1. CS4355.main(CS4355.java:39)
      1 frame