【问题标题】:Assertion: 13111:wrong type for field 3 != 4 - MongoDB C++ driver断言:13111:字段 3 的类型错误!= 4 - MongoDB C++ 驱动程序
【发布时间】:2013-07-21 19:47:28
【问题描述】:

在我的 MongoDB 数据库中,我有这种形式的文档:

   {    "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"

   }

其中一些包含数组事件有些不包含。

当我尝试使用 C++ MongoDB 驱动程序 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;

    }
  }

我收到此错误:

  timestamp: 2012-01-15T16:06:06.529
   HERE
   Qualifier ID: 15
   Value: 

   Qualifier ID: 56
   Value: Back

  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

总而言之,条件 bo.hasElement("Event") 始终为真。(???) 程序在这里刹车:

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

当数组Event没有成员时。

请帮忙!

【问题讨论】:

    标签: c++ mongodb assertion mongo-c-driver


    【解决方案1】:

    我可以为您提供有关该错误的更多信息:http://docs.mongodb.org/manual/reference/operator/type/#op._S_type 3 => 对象 4 => 数组

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-12-09
      • 2014-06-20
      相关资源
      最近更新 更多