• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

C++ BCON_INT32函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了C++中BCON_INT32函数的典型用法代码示例。如果您正苦于以下问题:C++ BCON_INT32函数的具体用法?C++ BCON_INT32怎么用?C++ BCON_INT32使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了BCON_INT32函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。

示例1: example

static void
example (void)
{
   bson_t *query;
   bson_t *doc;

   doc = BCON_NEW ("hello", "[", "{", "foo", BCON_UTF8 ("bar"), "}", "]");
   query = BCON_NEW ("hello.0.foo", BCON_UTF8 ("bar"));

   log_query (doc, query);
   check_match (doc, query);

   bson_destroy (doc);
   bson_destroy (query);

   /* i is > 1 or i < -1. */
   query = BCON_NEW ("$or", "[",
                     "{", "i", "{", "$gt", BCON_INT32 (1), "}", "}",
                     "{", "i", "{", "$lt", BCON_INT32 (-1), "}", "}", "]");

   doc = BCON_NEW ("i", BCON_INT32 (2));
   log_query (doc, query);
   check_match (doc, query);

   bson_destroy (doc);

   doc = BCON_NEW ("i", BCON_INT32 (0));
   log_query (doc, query);
   check_match (doc, query);

   bson_destroy (doc);
   bson_destroy (query);
}
开发者ID:3rf,项目名称:mongo-c-driver,代码行数:33,代码来源:example-matcher.c


示例2: test_mongoc_matcher_compare

static void
test_mongoc_matcher_compare (void)
{
   mongoc_matcher_t *matcher;
   compare_check checks[] = {
      { "$gt", 2, 2, false },
      { "$gte", 2, 2, true},
      { "$lt", 2, 2, false},
      { "$lte", 2, 2, true},
      { "$ne", 2, 2, false},
      { NULL }
   };
   bson_t *doc;
   bson_t *q;
   int i;

   for (i = 0; checks [i].op; i++) {
      doc = BCON_NEW ("a", BCON_INT32 (checks[i].doc));
      q = BCON_NEW ("a", "{", checks[i].op, BCON_INT32 (checks[i].query), "}");
      matcher = mongoc_matcher_new (q, NULL);
      assert (matcher);
      assert (mongoc_matcher_match (matcher, doc) == checks[i].expected);
      bson_destroy (q);
      bson_destroy (doc);
      mongoc_matcher_destroy (matcher);
   }
}
开发者ID:u2yg,项目名称:mongo-c-driver,代码行数:27,代码来源:test-mongoc-matcher.c


示例3: test_bson_iter_find_descendant

static void
test_bson_iter_find_descendant (void)
{
   bson_iter_t iter;
   bson_iter_t desc;
   bson_t *b;

   b = get_bson(BINARY_DIR"/dotkey.bson");
   assert(bson_iter_init(&iter, b));
   assert(bson_iter_find_descendant(&iter, "a.b.c.0", &desc));
   assert(BSON_ITER_HOLDS_INT32(&desc));
   assert(bson_iter_int32(&desc) == 1);
   bson_destroy(b);

   b = BCON_NEW ("foo", "{", "bar", "[", "{", "baz", BCON_INT32 (1), "}", "]", "}");
   assert (bson_iter_init (&iter, b));
   assert (bson_iter_find_descendant (&iter, "foo.bar.0.baz", &desc));
   assert (BSON_ITER_HOLDS_INT32 (&desc));
   assert (bson_iter_int32 (&desc) == 1);
   bson_destroy (b);

   b = BCON_NEW ("nModified", BCON_INT32 (1), "n", BCON_INT32 (2));
   assert (bson_iter_init (&iter, b));
   assert (bson_iter_find_descendant (&iter, "n", &desc));
   assert (!strcmp (bson_iter_key (&desc), "n"));
   bson_destroy (b);

   b = BCON_NEW ("", BCON_INT32 (1), "n", BCON_INT32 (2));
   assert (bson_iter_init (&iter, b));
   assert (bson_iter_find_descendant (&iter, "n", &desc));
   assert (!strcmp (bson_iter_key (&desc), "n"));
   bson_destroy (b);
}
开发者ID:Cabriter,项目名称:abelkhan,代码行数:33,代码来源:test-iter.c


示例4: test_extract_ctx

static void
test_extract_ctx (void)
{
   int32_t a, b, c;

   bson_t *bson =
      BCON_NEW ("a", BCON_INT32 (1), "b", BCON_INT32 (2), "c", BCON_INT32 (3));

   test_extract_ctx_helper (bson,
                            3,
                            "a",
                            BCONE_INT32 (a),
                            NULL,
                            "b",
                            BCONE_INT32 (b),
                            NULL,
                            "c",
                            BCONE_INT32 (c),
                            NULL);

   assert (a == 1);
   assert (b == 2);
   assert (c == 3);

   bson_destroy (bson);
}
开发者ID:rcsanchez97,项目名称:libbson,代码行数:26,代码来源:test-bcon-extract.c


示例5: test_mongoc_matcher_eq_doc

static void
test_mongoc_matcher_eq_doc (void)
{
   bson_t *spec;
   bson_t *doc;
   bson_error_t error;
   mongoc_matcher_t *matcher;

   /* {doc: {a: 1}} matches itself */
   spec = BCON_NEW ("doc", "{", "a", BCON_INT32 (1), "}");
   matcher = mongoc_matcher_new (spec, &error);
   BSON_ASSERT (matcher);
   BSON_ASSERT (mongoc_matcher_match (matcher, spec));

   /* {doc: {a: 1}} matches {doc: {a: 1}, foo: "whatever"} */
   doc = BCON_NEW ("doc", "{", "a", BCON_INT32 (1), "}",
                   "foo", BCON_UTF8 ("whatever"));
   BSON_ASSERT (mongoc_matcher_match (matcher, doc));
   bson_destroy (doc);

   /* {doc: {a: 1}} doesn't match {doc: 1} */
   doc = BCON_NEW ("doc", BCON_INT32 (1));
   BSON_ASSERT (!mongoc_matcher_match (matcher, doc));
   bson_destroy (doc);

   /* {doc: {a: 1}} doesn't match {doc: {}} */
   doc = BCON_NEW ("doc", "{", "}");
   BSON_ASSERT (!mongoc_matcher_match (matcher, doc));
   bson_destroy (doc);

   /* {doc: {a: 1}} doesn't match {doc: {a: 2}} */
   doc = BCON_NEW ("doc", "{", "a", BCON_INT32 (2), "}");
   BSON_ASSERT (!mongoc_matcher_match (matcher, doc));
   bson_destroy (doc);

   /* {doc: {a: 1}} doesn't match {doc: {b: 1}} */
   doc = BCON_NEW ("doc", "{", "b", BCON_INT32 (1), "}");
   BSON_ASSERT (!mongoc_matcher_match (matcher, doc));
   bson_destroy (doc);

   /* {doc: {a: 1}} doesn't match {doc: {a: 1, b: 1}} */
   doc = BCON_NEW ("doc", "{", "a", BCON_INT32 (1), "b", BCON_INT32 (1), "}");
   BSON_ASSERT (!mongoc_matcher_match (matcher, doc));
   bson_destroy (doc);

   /* {doc: {a: 1, b:1}} matches itself */
   bson_destroy (spec);
   mongoc_matcher_destroy (matcher);
   spec = BCON_NEW ("doc", "{", "a", BCON_INT32 (1), "b", BCON_INT32 (1), "}");
   matcher = mongoc_matcher_new (spec, &error);
   BSON_ASSERT (matcher);
   BSON_ASSERT (mongoc_matcher_match (matcher, spec));

   /* {doc: {a: 1, b:1}} doesn't match {doc: {a: 1}} */
   doc = BCON_NEW ("doc", "{", "a", BCON_INT32 (1), "}");
   BSON_ASSERT (!mongoc_matcher_match (matcher, doc));
   bson_destroy (spec);
   bson_destroy (doc);
   mongoc_matcher_destroy (matcher);
}
开发者ID:u2yg,项目名称:mongo-c-driver,代码行数:60,代码来源:test-mongoc-matcher.c


示例6: main

int
main (int argc, char *argv[])
{
   int i;
   int n;
   int bcon;
   bson_t bson, foo, bar, baz;
   bson_init (&bson);

   if (argc != 3) {
      fprintf (stderr,
               "usage: bcon-speed NUM_ITERATIONS [y|n]\n"
               "\n"
               "  y = perform speed tests with bcon\n"
               "  n = perform speed tests with bson_append\n"
               "\n");
      return EXIT_FAILURE;
   }

   assert (argc == 3);

   n = atoi (argv[1]);
   bcon = (argv[2][0] == 'y') ? 1 : 0;

   for (i = 0; i < n; i++) {
      if (bcon) {
         BCON_APPEND (&bson,
                      "foo",
                      "{",
                      "bar",
                      "{",
                      "baz",
                      "[",
                      BCON_INT32 (1),
                      BCON_INT32 (2),
                      BCON_INT32 (3),
                      "]",
                      "}",
                      "}");
      } else {
         bson_append_document_begin (&bson, "foo", -1, &foo);
         bson_append_document_begin (&foo, "bar", -1, &bar);
         bson_append_array_begin (&bar, "baz", -1, &baz);
         bson_append_int32 (&baz, "0", -1, 1);
         bson_append_int32 (&baz, "1", -1, 2);
         bson_append_int32 (&baz, "2", -1, 3);
         bson_append_array_end (&bar, &baz);
         bson_append_document_end (&foo, &bar);
         bson_append_document_end (&bson, &foo);
      }

      bson_reinit (&bson);
   }

   bson_destroy (&bson);

   return 0;
}
开发者ID:rcsanchez97,项目名称:libbson,代码行数:58,代码来源:bcon-speed.c


示例7: main

int
main (int   argc,
      char *argv[])
{
   mongoc_collection_t *collection;
   mongoc_client_t *client;
   bson_error_t error;
   bson_t *query;
   bson_t *update;
   bson_t reply;
   char *str;

   mongoc_init ();

   client = mongoc_client_new ("mongodb://127.0.0.1:27017/");
   collection = mongoc_client_get_collection (client, "test", "test");

   /*
    * Build our query, {"cmpxchg": 1}
    */
   query = BCON_NEW ("cmpxchg", BCON_INT32 (1));

   /*
    * Build our update. {"$set": {"cmpxchg": 2}}
    */
   update = BCON_NEW ("$set", "{", "cmpxchg", BCON_INT32 (2), "}");

   /*
    * Submit the findAndModify.
    */
   if (!mongoc_collection_find_and_modify (collection, query, NULL, update, NULL, false, false, true, &reply, &error)) {
      fprintf (stderr, "find_and_modify() failure: %s\n", error.message);
      return 1;
   }

   /*
    * Print the result as JSON.
    */
   str = bson_as_json (&reply, NULL);
   printf ("%s\n", str);
   bson_free (str);

   /*
    * Cleanup.
    */
   bson_destroy (query);
   bson_destroy (update);
   bson_destroy (&reply);
   mongoc_collection_destroy (collection);
   mongoc_client_destroy (client);

   mongoc_cleanup ();

   return 0;
}
开发者ID:3rf,项目名称:mongo-c-driver,代码行数:55,代码来源:find-and-modify.c


示例8: main

int
main (int   argc,
      char *argv[])
{

    bson_t * query;


    /*
    time_t oid_thinks_time;  //what time does the OID think it is
    bson_oid_t oid;
    bson_oid_t *oid_pointer = &oid;
    bson_oid_init (&oid, NULL);  // get a standard ObjectId
    oid_thinks_time = bson_oid_get_time_t (&oid); //It was just made
    printf ("The OID was generated at %u\n", (unsigned) oid_thinks_time); //prove it



    time_t  ts = time(NULL);  //make a new time
    struct tm * timeinfo = localtime(&ts);
    timeinfo->tm_year = 2014-1900;  //-1900 because time.h
    timeinfo->tm_mon  = 12 - 1;     // time.h off by one (starts at 0)
    timeinfo->tm_mday = 25;
    ts = mktime(timeinfo);          // create the time
    u_int32_t ts_uint = (uint32_t)ts;
    ts_uint = BSON_UINT32_TO_BE (ts_uint); //BSON wants big endian time
    memcpy (&oid_pointer->bytes[0], &ts_uint, sizeof (ts_uint));  //overwrite the first 4 bytes with user selected time
    oid_thinks_time = bson_oid_get_time_t (&oid);
    printf ("The OID was fixed to time %u\n", (unsigned) oid_thinks_time);//prove it
*/

    query = BCON_NEW ("ping", BCON_INT32 (1));
    query = BCON_NEW("$and","[",
                     "{", "a", BCON_INT32(1), "}",
                     "{", "yyyyyyy", "{", "$ne", BCON_UTF8("xxxxxxxxxx"), "}", "}","]");

    bson_t *doc;

    query = BCON_NEW (
                    "$and", "[", "{", "_id", BCON_INT32(1), "}",
                                 "{", "yyyyyy", "{", "$ne", BCON_UTF8 ("xxxxxxx"), "}", "}","]"
                    );
    query = BCON_NEW("$and","[",
                     "{", "timestamp", "{", "$eq", BCON_INT64(1111111111112), "}", "}",
                     "{", "timestamp", "{", "$gte", BCON_INT64(1111111111111), "}", "}",
                     "{", "timestamp", "{", "$lt", BCON_INT64(1111111111110), "}", "}","]");
    //prove it looks right

    size_t s;
    char * as_json;
    as_json = bson_as_json(query, &s);
    printf("%s\n", as_json);
    return 0;
}
开发者ID:bauman,项目名称:bsonsearch,代码行数:54,代码来源:bcon_samples.c


示例9: bulk3

static void
bulk3 (mongoc_collection_t *collection)
{
   mongoc_bulk_operation_t *bulk;
   bson_error_t error;
   bson_t *query;
   bson_t *doc;
   bson_t reply;
   char *str;
   bool ret;

   /* false indicates unordered */
   bulk = mongoc_collection_create_bulk_operation (collection, false, NULL);

   /* Add a document */
   doc = BCON_NEW ("_id", BCON_INT32 (1));
   mongoc_bulk_operation_insert (bulk, doc);
   bson_destroy (doc);

   /* remove {_id: 2} */
   query = BCON_NEW ("_id", BCON_INT32 (2));
   mongoc_bulk_operation_remove_one (bulk, query);
   bson_destroy (query);

   /* insert {_id: 3} */
   doc = BCON_NEW ("_id", BCON_INT32 (3));
   mongoc_bulk_operation_insert (bulk, doc);
   bson_destroy (doc);

   /* replace {_id:4} {'i': 1} */
   query = BCON_NEW ("_id", BCON_INT32 (4));
   doc = BCON_NEW ("i", BCON_INT32 (1));
   mongoc_bulk_operation_replace_one (bulk, query, doc, false);
   bson_destroy (query);
   bson_destroy (doc);

   ret = mongoc_bulk_operation_execute (bulk, &reply, &error);

   str = bson_as_json (&reply, NULL);
   printf ("%s\n", str);
   bson_free (str);

   if (!ret) {
      printf ("Error: %s\n", error.message);
   }

   bson_destroy (&reply);
   mongoc_bulk_operation_destroy (bulk);
}
开发者ID:3rf,项目名称:mongo-c-driver,代码行数:49,代码来源:bulk3.c


示例10: test_inline_array

static void
test_inline_array (void)
{
   int32_t a, b;

   bson_t *bcon = BCON_NEW ("foo", "[", BCON_INT32 (1), BCON_INT32 (2), "]");

   assert (
      BCON_EXTRACT (bcon, "foo", "[", BCONE_INT32 (a), BCONE_INT32 (b), "]"));

   assert (a == 1);
   assert (b == 2);

   bson_destroy (bcon);
}
开发者ID:rcsanchez97,项目名称:libbson,代码行数:15,代码来源:test-bcon-extract.c


示例11: main

int main(void)
{
   mongoc_collection_t *collection;
   mongoc_database_t *database;
   mongoc_client_t *client;
   bson_error_t error;
   bson_t *options;

   client = mongoc_client_new ("mongodb://localhost:27017/admin");
   database = mongoc_client_get_database (client, "databaseName");

   options = BCON_NEW ( "validator", "{", "age", "{", "$lte", BCON_INT32 (34), "}", "}", "validationAction", BCON_UTF8 ("error"), "validationLevel", BCON_UTF8 ("moderate"));

   collection = mongoc_database_create_collection (database, "collectionName", options, &error);
   if (!collection) {
      fprintf(stderr, "Got error: \"%s\" on line %d\n", error.message, __LINE__);
      return 1;
   }

   fam_flags (collection);
   fam_bypass (collection);
   fam_update (collection);
   fam_fields (collection);
   fam_sort (collection);

   mongoc_collection_drop (collection, NULL);
   bson_destroy (options);
   mongoc_database_destroy (database);
   mongoc_collection_destroy (collection);
   mongoc_client_destroy (client);

   return 0;
}
开发者ID:AbhimanyuAryan,项目名称:treefrog-framework,代码行数:33,代码来源:fam.c


示例12: test_suite

void test_suite (mongoc_database_t   *db,
                 mongoc_collection_t *collection)
{
   bson_error_t error;
   bson_t query = BSON_INITIALIZER;
   int64_t count;
   bson_t *options, *pipeline;
   double start_time, end_time, delta_time;
   mongoc_cursor_t *cursor;

   count = mongoc_collection_count (collection, MONGOC_QUERY_NONE, &query, 0, 0, NULL, &error);
   printf ("mongoc_collection_count count: %"PRId64"\n", count);
   options = BCON_NEW ("cursor", "{", "}", "allowDiskUse", BCON_BOOL (1));
   pipeline = BCON_NEW (
      "pipeline", "[",
          "{",
             "$match", "{",
             "}",
          "}",
          "{",
             "$project", "{",
                "text", BCON_INT32 (1),
             "}",
          "}",
       "]"
   );
   start_time = dtimeofday ();
   cursor = mongoc_collection_aggregate (collection, MONGOC_QUERY_NONE, pipeline, options, NULL);
   count = mongoc_cursor_dump (cursor);
   end_time = dtimeofday ();
   delta_time = end_time - start_time + 0.0000001;
   printf ("mongoc_cursor_dump: secs: %.2f, count: %"PRId64", %.2f docs/sec\n", delta_time, count, count/delta_time);
}
开发者ID:delort,项目名称:mongo-musicbrainz,代码行数:33,代码来源:test-aggregate.c


示例13: bulk1

static void
bulk1 (mongoc_collection_t *collection)
{
   mongoc_bulk_operation_t *bulk;
   bson_error_t error;
   bson_t *doc;
   bson_t reply;
   char *str;
   bool ret;
   int i;

   bulk = mongoc_collection_create_bulk_operation (collection, true, NULL);

   for (i = 0; i < 10000; i++) {
      doc = BCON_NEW ("i", BCON_INT32 (i));
      mongoc_bulk_operation_insert (bulk, doc);
      bson_destroy (doc);
   }

   ret = mongoc_bulk_operation_execute (bulk, &reply, &error);

   str = bson_as_json (&reply, NULL);
   printf ("%s\n", str);
   bson_free (str);

   if (!ret) {
      fprintf (stderr, "Error: %s\n", error.message);
   }

   bson_destroy (&reply);
   mongoc_bulk_operation_destroy (bulk);
}
开发者ID:3rf,项目名称:mongo-c-driver,代码行数:32,代码来源:bulk1.c


示例14: main

int
main (int argc,
      char *argv[])
{
   bson_t *options;
   bson_error_t error;
   mongoc_client_t *client;
   mongoc_collection_t *collection;
   mongoc_database_t *database;

   mongoc_init ();

   client = mongoc_client_new ("mongodb://localhost/");
   database = mongoc_client_get_database (client, "testasdf");

   /* Create schema validator */
   options = BCON_NEW ("validator", "{", "number", "{", "$gte", BCON_INT32 (5), "}", "}");
   collection = mongoc_database_create_collection (database, "collname", options, &error);

   if (collection) {
      bulk5_fail (collection);
      bulk5_success (collection);
      mongoc_collection_destroy (collection);
   } else {
      fprintf(stderr, "Couldn't create collection: '%s'\n", error.message);
   }

   bson_free (options);
   mongoc_database_destroy (database);
   mongoc_client_destroy (client);

   mongoc_cleanup ();

   return 0;
}
开发者ID:3rf,项目名称:mongo-c-driver,代码行数:35,代码来源:bulk5.c


示例15: print_pipeline

static void
print_pipeline (mongoc_collection_t *collection)
{
   mongoc_cursor_t *cursor;
   bson_error_t error;
   const bson_t *doc;
   bson_t *pipeline;
   char *str;

   pipeline = BCON_NEW ("pipeline", "[",
      "{", "$group", "{", "_id", "$state", "total_pop", "{", "$sum", "$pop", "}", "}", "}",
      "{", "$match", "{", "total_pop", "{", "$gte", BCON_INT32 (10000000), "}", "}", "}",
   "]");

   cursor = mongoc_collection_aggregate (collection, MONGOC_QUERY_NONE, pipeline, NULL, NULL);

   while (mongoc_cursor_next (cursor, &doc)) {
      str = bson_as_json (doc, NULL);
      printf ("%s\n", str);
      bson_free (str);
   }

   if (mongoc_cursor_error (cursor, &error)) {
      fprintf (stderr, "Cursor Failure: %s\n", error.message);
   }

   mongoc_cursor_destroy (cursor);
   bson_destroy (pipeline);
}
开发者ID:Machyne,项目名称:mongo-c-driver,代码行数:29,代码来源:aggregation1.c


示例16: test_skip

static void
test_skip (void)
{
   bson_t *bcon = BCON_NEW (
      "hello", "world",
      "foo", "{",
      "bar", BCON_INT32 (10),
      "}"
      );

   assert (BCON_EXTRACT (bcon,
                         "hello", BCONE_SKIP (BSON_TYPE_UTF8),
                         "foo", "{",
                         "bar", BCONE_SKIP (BSON_TYPE_INT32),
                         "}"
                         ));

   assert (!BCON_EXTRACT (bcon,
                          "hello", BCONE_SKIP (BSON_TYPE_UTF8),
                          "foo", "{",
                          "bar", BCONE_SKIP (BSON_TYPE_INT64),
                          "}"
                          ));

   bson_destroy (bcon);
}
开发者ID:Cabriter,项目名称:abelkhan,代码行数:26,代码来源:test-bcon-extract.c


示例17: test_inline_doc

static void
test_inline_doc (void)
{
   int32_t a, b;

   bson_t *bcon =
      BCON_NEW ("foo", "{", "b", BCON_INT32 (2), "a", BCON_INT32 (1), "}");

   BSON_ASSERT (BCON_EXTRACT (
      bcon, "foo", "{", "a", BCONE_INT32 (a), "b", BCONE_INT32 (b), "}"));

   BSON_ASSERT (a == 1);
   BSON_ASSERT (b == 2);

   bson_destroy (bcon);
}
开发者ID:ShaneHarvey,项目名称:libbson,代码行数:16,代码来源:test-bcon-extract.c


示例18: test_nested

static void
test_nested (void)
{
   const char *utf8;
   int i32;

   bson_t *bcon = BCON_NEW (
      "hello", "world",
      "foo", "{",
      "bar", BCON_INT32 (10),
      "}"
      );

   assert (BCON_EXTRACT (bcon,
                         "hello", BCONE_UTF8 (utf8),
                         "foo", "{",
                         "bar", BCONE_INT32 (i32),
                         "}"
                         ));

   assert (strcmp ("world", utf8) == 0);
   assert (i32 == 10);

   bson_destroy (bcon);
}
开发者ID:Cabriter,项目名称:abelkhan,代码行数:25,代码来源:test-bcon-extract.c


示例19: test_mongoc_matcher_in_basic

static void
test_mongoc_matcher_in_basic (void)
{
   mongoc_matcher_t *matcher;
   bson_error_t error;
   bool r;
   bson_t *spec;
   bson_t doc = BSON_INITIALIZER;

   spec = BCON_NEW ("key", "{",
                       "$in", "[",
                          BCON_INT32 (1),
                          BCON_INT32 (2),
                          BCON_INT32 (3),
                       "]",
                    "}");

   matcher = mongoc_matcher_new (spec, &error);
   r = mongoc_matcher_match (matcher, &doc);
   ASSERT (!r);

   bson_reinit (&doc);
   bson_append_int32 (&doc, "key", 3, 1);
   r = mongoc_matcher_match (matcher, &doc);
   ASSERT (r);

   bson_reinit (&doc);
   bson_append_int32 (&doc, "key", 3, 2);
   r = mongoc_matcher_match (matcher, &doc);
   ASSERT (r);

   bson_reinit (&doc);
   bson_append_int32 (&doc, "key", 3, 3);
   r = mongoc_matcher_match (matcher, &doc);
   ASSERT (r);

   bson_reinit (&doc);
   bson_append_int32 (&doc, "key", 3, 4);
   r = mongoc_matcher_match (matcher, &doc);
   ASSERT (!r);

   bson_destroy (&doc);
   bson_destroy (spec);
   mongoc_matcher_destroy (matcher);
}
开发者ID:u2yg,项目名称:mongo-c-driver,代码行数:45,代码来源:test-mongoc-matcher.c


示例20: test_invalid_write_concern

static void
test_invalid_write_concern (void)
{
   mongoc_bulk_write_flags_t write_flags = MONGOC_BULK_WRITE_FLAGS_INIT;
   mongoc_write_command_t command;
   mongoc_write_result_t result;
   mongoc_collection_t *collection;
   mongoc_client_t *client;
   mongoc_write_concern_t *write_concern;
   mongoc_server_stream_t *server_stream;
   bson_t *doc;
   bson_t reply = BSON_INITIALIZER;
   bson_error_t error;
   bool r;

   client = test_framework_client_new ();
   assert(client);

   collection = get_test_collection(client, "test_invalid_write_concern");
   assert(collection);

   write_concern = mongoc_write_concern_new();
   assert(write_concern);
   mongoc_write_concern_set_w(write_concern, 0);
   mongoc_write_concern_set_journal(write_concern, true);
   assert(!mongoc_write_concern_is_valid (write_concern));

   doc = BCON_NEW("_id", BCON_INT32(0));

   _mongoc_write_command_init_insert(&command, doc, write_flags,
                                     ++client->cluster.operation_id, true);
   _mongoc_write_result_init (&result);
   server_stream = mongoc_cluster_stream_for_writes (&client->cluster, &error);
   ASSERT_OR_PRINT (server_stream, error);
   _mongoc_write_command_execute (&command, client, server_stream,
                                  collection->db, collection->collection,
                                  write_concern, 0, &result);

   r = _mongoc_write_result_complete (&result, 2, collection->write_concern,
                                      &reply, &error);

   assert(!r);
   ASSERT_CMPINT(error.domain, ==, MONGOC_ERROR_COMMAND);
   ASSERT_CMPINT(error.code, ==, MONGOC_ERROR_COMMAND_INVALID_ARG);

   _mongoc_write_command_destroy (&command);
   _mongoc_write_result_destroy (&result);

   bson_destroy(doc);
   mongoc_server_stream_cleanup (server_stream);
   mongoc_collection_destroy(collection);
   mongoc_client_destroy(client);
   mongoc_write_concern_destroy(write_concern);
}
开发者ID:Cabriter,项目名称:abelkhan,代码行数:54,代码来源:test-write-commands.c



注:本文中的BCON_INT32函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C++ BCON_NEW函数代码示例发布时间:2022-05-30
下一篇:
C++ BCM_DEBUG_PRINT函数代码示例发布时间:2022-05-30
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap