title: mongodb c++ driver does not upsert
body: <p>In mongodb, I have this doc:</p>
  
  <pre><code>{
  "_id" : ObjectId("53e157918b3354f7157142d2"),
  "packet" : [ 
      {
          "datetime" : ISODate("2014-08-05T16:16:46.337Z"),
          "signallingType" : "M2PA",
          "clgNum" : "",
          "cldNum" : "",
          "opc" : "6406",
          "dpc" : "327",
          "transState" : "continue",
          "otid" : "M2PA042f2ee0",
          "dtid" : "",
          "sccpCalling" : "523331461111",
          "sccpCalled" : "52333033342222",
          "imsi" : "",
          "operation" : "sendAuthenticationInfo (56)",
          "camelClgNum" : "",
          "camelCldNum" : "",
          "camelCallRefNum" : "",
          "camelImsi" : "",
          "camelEvent" : "",
          "camelReleaseCause" : "",
          "pcapFileName" : "/home/monitor/tmp/gsm_eth2_06700_20140805165712.pcap",
          "message" : "dddvid"
      }
  ]
  </code></pre>
  
  <p>}</p>
  
  <p>And If I execute from the shell the following:</p>
  
  <pre><code>db.packets.update( 
  { $and: [ 
      { $or: [ 
          { "packet.otid": { $in: [ "M2PA042f2ee0" ] } },
          { "packet.dtid": { $in: [ "M2PA042f2ee0" ] } }
      ] },
      { $or: [
          { "packet.sccpCalling": { $in: [ "523331461111", "52333033342222" ] } },
          { "packet.sccpCalled": { $in: [ "523331461111", "52333033342222" ] } }
      ] }
  ] }, 
  { $push: { packet: { datetime: new Date(1407255406337) } } }, true 
  )
  </code></pre>
  
  <p>The doc gets upserted without problems.
  Now, with c++ I do:</p>
  
  <pre><code>class Packet {
  
  public:
      std::string packetDate;
      std::string signallingType;
      int creationTimeStamp;
      std::string clgNum;
      std::string cldNum;
      std::string opc;
      std::string dpc;
      std::string transState;
      std::string otid;
      std::string dtid;
      std::string message;
      std::string sccpCalling;
      std::string sccpCalled;
      std::string imsi;
      std::string operation;
      std::string camelClgNum;
      std::string camelCldNum;
      std::string camelCallRefNum;
      std::string camelImsi;
      std::string camelEvent;
      std::string camelReleaseCause;
      std::string pcapFile;
  ...
  </code></pre>
  
  <p>I was asked to show how I create "query_otid_or" and query_sccp_or":</p>
  
  <pre><code>mongo::BSONObj query;
  mongo::BSONObj objError;
  mongo::BSONObj query_otid;
  mongo::BSONObj query_dtid;
  mongo::BSONObj query_sccpCalling;
  mongo::BSONObj query_sccpCalled;
  mongo::BSONObj query_otid_or;
  mongo::BSONObj query_sccp_or;
  ...
          tcapValuesArray.clear(); sccpValuesArray.clear();
          if( (it)-&gt;otid.length() &gt; 0 ){
              tcapValuesArray.push_back( (it)-&gt;otid );
          }
  
          if( (it)-&gt;dtid.length() &gt; 0 ){
              tcapValuesArray.push_back( (it)-&gt;dtid );
          }
  
          if( (it)-&gt;sccpCalling.length() &gt; 0 ){
              sccpValuesArray.push_back( (it)-&gt;sccpCalling );
          }
          if( (it)-&gt;sccpCalled.length() &gt; 0 ){
              sccpValuesArray.push_back( (it)-&gt;sccpCalled );
          }
  
          query_otid = BSON( "\"packet.otid\"" &lt;&lt;  BSON( "$in" &lt;&lt; tcapValuesArray ) );
          query_dtid = BSON( "\"packet.dtid\"" &lt;&lt;  BSON( "$in" &lt;&lt; tcapValuesArray ) );
  
          query_sccpCalling = BSON( "\"packet.sccpCalling\"" &lt;&lt; BSON( "$in" &lt;&lt; sccpValuesArray ) );
          query_sccpCalled = BSON( "\"packet.sccpCalled\"" &lt;&lt; BSON( "$in" &lt;&lt; sccpValuesArray ) );
  
          query_otid_or = mongo::OR( query_otid, query_dtid );
          query_sccp_or = mongo::OR( query_sccpCalling, query_sccpCalled );
  
  ...
  
  c.update("tracer.packets",
    BSON( "$and" &lt;&lt; BSON_ARRAY( query_otid_or &lt;&lt; query_sccp_or ) ),
    BSON( "$push" &lt;&lt; BSON("packet" &lt;&lt; BSON( "datetime" &lt;&lt; mongo::Date_t( atoll( ((it)-&gt;packetDate.substr(0,10) + (it)-&gt;packetDate.substr(11,3)).c_str() ))))), 
    true, 
    true);
  </code></pre>
  
  <p>It doesn't work, a new record is inserted... though it is exactly the same command...</p>
  
  <p>Anybody got any ideas??</p>