Ejemplo n.º 1
0
static void
assert_bson_equal (const bson_t *a,
                   const bson_t *b)
{
   const bson_uint8_t *data1 = bson_get_data(a);
   const bson_uint8_t *data2 = bson_get_data(b);
   bson_uint32_t i;

   if (!bson_equal(a, b)) {
      for (i = 0; i < MAX(a->len, b->len); i++) {
         if (i >= a->len) {
            printf("a is too short len=%u\n", a->len);
            abort();
         } else if (i >= b->len) {
            printf("b is too short len=%u\n", b->len);
            abort();
         }
         if (data1[i] != data2[i]) {
            printf("a[%u](0x%02x,%u) != b[%u](0x%02x,%u)\n",
                   i, data1[i], data1[i], i, data2[i], data2[i]);
            abort();
         }
      }
   }
}
Ejemplo n.º 2
0
bool _aggregate_have_same_id(bson_t *doc, bson_value_t *id_value) {;
    bson_value_t *doc_id_value = _aggregate_get_value_at_key(doc, "_id");

    bson_t new_doc1;
    bson_init (&new_doc1);
    bson_append_value(&new_doc1, "_id", -1, doc_id_value);

    bson_t new_doc2;
    bson_init (&new_doc2);
    bson_append_value(&new_doc2, "_id", -1, id_value);

    bool are_equal = bson_equal(&new_doc1, &new_doc2);
    bson_value_destroy(doc_id_value);

    return are_equal;
}