Assertion: 13111:wrong type for field 3 != 4 - MongoDB C++ driver -
in mongodb database have documents of 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 array event don't.
when i'm trying process data using 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> = bo.getfield("event").array(); // ---> @ line breaks!! (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 error:
timestamp: 2012-01-15t16:06:06.529 here qualifier id: 15 value: qualifier id: 56 value: 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: 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 field (event) 3 != 4 caught wrong type field (event) 3 != 4
in conclusion condition bo.haselement("event") true.(???) program brakes here:
std::vector<bsonelement> = bo.getfield("event").array();
when array event has no members.
pease help!
i can more info error: http://docs.mongodb.org/manual/reference/operator/type/#op._s_type 3 => object 4 => array
Comments
Post a Comment