Uploaded image for project: 'Core Server'
  1. Core Server
  2. SERVER-10278

Assertion: 13111:wrong type for field 3 != 4 - MongoDB C++ driver

    • Type: Icon: Question Question
    • Resolution: Done
    • Priority: Icon: Minor - P4 Minor - P4
    • None
    • Affects Version/s: 2.4.0
    • Component/s: Internal Client
    • None
    • Environment:
      Ubuntu 13.04, MongoDB C++ 2.4
    • None
    • 0
    • None
    • None
    • None
    • None
    • None
    • None

      In my MongoDB database I have documents of this form:

      { "timestamp" : "2012-01-15T17:56:14.85",
        "Event" : [ { "id" : "1851236846",
                      "qualifier_id" : "209"
                  },
                  {
                      "id" : "378258775",
                      "qualifier_id" : "57",
                      "value" : "1"
                  }
              ]
          }
      
         {   "timestamp" : "2012-01-15T16:06:09.378"
      
         }
      

      Some of them contain the array Event some don't.

      When I'm trying to process the data using the C++ MongoDB driver 2.4:

      while (cursor->more()) { 
        BSONObj bo = cursor->next();
        cout << "timestamp: " << bo.getStringField("timestamp") << std::endl;
      
        if(bo.hasElement("Event")) {
          cout<<"HERE"<< endl;
      
          std::vector<BSONElement> be = bo.getField("Event").Array(); // ---> at this line breaks!!
      
          for (unsigned int j = 0; j < be.size(); j++) {
                    BSONObj bo2 = be[j].embeddedObject();
                    cout << "Qualifier ID: " << bo2.getStringField("qualifier_id") << std::endl;
                    cout << "Value: " << bo2.getStringField("value")<< std::endl;
          }
        }
      

      I get this error:

      timestamp: 2012-01-15T16:06:07.560
         HERE
         Qualifier ID: 212
         Value: 14.6
      
         Qualifier ID: 141
         Value: 89.2
      
         Qualifier ID: 213
         Value: 5.9
      
         Qualifier ID: 56
         Value: Back
      
         Qualifier ID: 140
         Value: 46.7
      
        timestamp: 2012-01-15T16:06:09.378
        HERE
        Sun Jul 21 20:06:16.974 
      Assertion: 13111:wrong type for field (Event) 3 != 4
        caught wrong type for field (Event) 3 != 4
      

      In conclusion the condition bo.hasElement("Event") is always true.(???) The program brakes here:

         std::vector<BSONElement> be = bo.getField("Event").Array();

      When the array Event has no members.

            Assignee:
            Unassigned Unassigned
            Reporter:
            gauss Michael Wayne
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated:
              Resolved: