您当前的位置:首页 > IT编程 > C++
| C语言 | Java | VB | VC | python | Android | TensorFlow | C++ | oracle | 学术与代码 | cnn卷积神经网络 | gnn | 图像修复 | Keras | 数据集 | Neo4j | 自然语言处理 | 深度学习 | 医学CAD | 医学影像 | 超参数 | pointnet | pytorch | 异常检测 | Transformers | 情感分类 | 知识图谱 |

自学教程:C++ BSON_APPEND_UTF8函数代码示例

51自学网 2021-06-01 19:53:01
  C++
这篇教程C++ BSON_APPEND_UTF8函数代码示例写得很实用,希望能帮到您。

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

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

示例1: mongo_set_oauth_key

static int mongo_set_oauth_key(oauth_key_data_raw *key) {  mongoc_collection_t * collection = mongo_get_collection("oauth_key");  if(!collection)    return -1;  bson_t query;  bson_init(&query);  BSON_APPEND_UTF8(&query, "kid", (const char *)key->kid);  bson_t doc;  bson_init(&doc);  BSON_APPEND_UTF8(&doc, "kid", (const char *)key->kid);  BSON_APPEND_UTF8(&doc, "as_rs_alg", (const char *)key->as_rs_alg);  BSON_APPEND_UTF8(&doc, "ikm_key", (const char *)key->ikm_key);  BSON_APPEND_INT64(&doc, "timestamp", (int64_t)key->timestamp);  BSON_APPEND_INT32(&doc, "lifetime", (int32_t)key->lifetime);  int ret = -1;  if (!mongoc_collection_update(collection, MONGOC_UPDATE_UPSERT, &query, &doc, NULL, NULL)) {    TURN_LOG_FUNC(TURN_LOG_LEVEL_ERROR, "Error inserting/updating oauth key information/n");  } else {    ret = 0;  }  mongoc_collection_destroy(collection);  bson_destroy(&doc);  bson_destroy(&query);  return ret;}
开发者ID:SteppeChange,项目名称:coturn,代码行数:31,


示例2: mongo_set_user_key

static int mongo_set_user_key(u08bits *usname, u08bits *realm, const char *key) {  mongoc_collection_t * collection = mongo_get_collection("turnusers_lt"); 	if(!collection)    return -1;      bson_t query;  bson_init(&query);  BSON_APPEND_UTF8(&query, "name", (const char *)usname);  BSON_APPEND_UTF8(&query, "realm", (const char *)realm);        bson_t doc;  bson_init(&doc);  BSON_APPEND_UTF8(&doc, "name", (const char *)usname);  BSON_APPEND_UTF8(&doc, "realm", (const char *)realm);  BSON_APPEND_UTF8(&doc, "hmackey", (const char *)key);  int ret = -1;    if (!mongoc_collection_update(collection, MONGOC_UPDATE_UPSERT, &query, &doc, NULL, NULL)) {    TURN_LOG_FUNC(TURN_LOG_LEVEL_ERROR, "Error inserting/updating user key information/n");  } else {    ret = 0;  }  mongoc_collection_destroy(collection);  bson_destroy(&doc);  bson_destroy(&query);  return ret;}
开发者ID:SteppeChange,项目名称:coturn,代码行数:29,


示例3: mongo_set_admin_user

static int mongo_set_admin_user(const u08bits *usname, const u08bits *realm, const password_t pwd){	mongoc_collection_t * collection = mongo_get_collection("admin_user");	if(!collection)    return -1;	bson_t query;	bson_init(&query);	BSON_APPEND_UTF8(&query, "name", (const char *)usname);	bson_t doc;	bson_init(&doc);	BSON_APPEND_UTF8(&doc, "name", (const char *)usname);	BSON_APPEND_UTF8(&doc, "realm", (const char *)realm);	BSON_APPEND_UTF8(&doc, "password", (const char *)pwd);	int ret = -1;	if (!mongoc_collection_update(collection, MONGOC_UPDATE_UPSERT, &query, &doc, NULL, NULL)) {		TURN_LOG_FUNC(TURN_LOG_LEVEL_ERROR, "Error inserting/updating admin user information/n");	} else {		ret = 0;	}	mongoc_collection_destroy(collection);	bson_destroy(&doc);	bson_destroy(&query);	return ret;}
开发者ID:SteppeChange,项目名称:coturn,代码行数:29,


示例4: mongo_add_origin

static int mongo_add_origin(u08bits *origin, u08bits *realm){	mongoc_collection_t * collection = mongo_get_collection("realm");	if(!collection)		return -1;    	int ret = -1;	u08bits realm0[STUN_MAX_REALM_SIZE+1] = "/0";	if(!realm) realm=realm0;  	bson_t query, doc, child;	bson_init(&query);	BSON_APPEND_UTF8(&query, "realm", (const char *)realm);	bson_init(&doc);	bson_append_document_begin(&doc, "$addToSet", -1, &child);	BSON_APPEND_UTF8(&child, "origin", (const char *)origin);	bson_append_document_end(&doc, &child);	if (!mongoc_collection_update(collection, MONGOC_UPDATE_UPSERT, &query, &doc, NULL, NULL)) {		TURN_LOG_FUNC(TURN_LOG_LEVEL_ERROR, "Error inserting/updating realm origin information/n");	} else {		ret = 0;	}	mongoc_collection_destroy(collection);	bson_destroy(&query);	bson_destroy(&doc);	return ret;}
开发者ID:SteppeChange,项目名称:coturn,代码行数:30,


示例5: sim_parser_connect_test4

/* check  version */static gboolean sim_parser_connect_test4 (void){{  bson_t *bson_connect = bson_new ();  bson_t child;  SimParser *parser = NULL;  SimCommand *cmd = NULL;  gboolean result = FALSE;  uint8_t uuid[]={0x07,0x92,0xd6,0x72,0xf4,0xce,0x11,0xe4,0x9d,0xe2,0x00,0x0c,0x29,0xd9,0x46,0xde};  bson_append_document_begin (bson_connect,"connect", -1, &child);  BSON_APPEND_UTF8 (&child, "id", "bad id");  BSON_APPEND_INT32 (&child, "type", SIM_SESSION_TYPE_WEB);  BSON_APPEND_UTF8 (&child, "version", "x.x.x");  if (bson_append_binary (&child, "sensor_id", -1, BSON_SUBTYPE_UUID, uuid, 16) == FALSE)    return FALSE;  bson_append_document_end (bson_connect, &child);  do{    if ((parser = sim_parser_new()) == NULL)    {       result = FALSE;      break;    }    if ((cmd = sim_parser_bson (parser, bson_get_data (bson_connect), bson_connect->len)) != NULL)    {      result = FALSE;      break;    }    result = TRUE;  } while (0);  return result;}}
开发者ID:jackpf,项目名称:ossim-arc,代码行数:35,


示例6: copy_labels_plus_unknown_commit_result

static voidcopy_labels_plus_unknown_commit_result (const bson_t *src, bson_t *dst){   bson_iter_t iter;   bson_iter_t src_label;   bson_t dst_labels;   char str[16];   uint32_t i = 0;   const char *key;   BSON_APPEND_ARRAY_BEGIN (dst, "errorLabels", &dst_labels);   BSON_APPEND_UTF8 (&dst_labels, "0", UNKNOWN_COMMIT_RESULT);   /* append any other errorLabels already in "src" */   if (bson_iter_init_find (&iter, src, "errorLabels") &&       bson_iter_recurse (&iter, &src_label)) {      while (bson_iter_next (&src_label) && BSON_ITER_HOLDS_UTF8 (&src_label)) {         if (strcmp (bson_iter_utf8 (&src_label, NULL),                     UNKNOWN_COMMIT_RESULT) != 0) {            i++;            bson_uint32_to_string (i, &key, str, sizeof str);            BSON_APPEND_UTF8 (               &dst_labels, key, bson_iter_utf8 (&src_label, NULL));         }      }   }   bson_append_array_end (dst, &dst_labels);}
开发者ID:samantharitter,项目名称:mongo-c-driver,代码行数:29,


示例7: dir_getBSON

bson_t* dir_getBSON(dir_t *dir) {	bson_t *bson = bson_new();	BSON_APPEND_UTF8(bson, "_id", dir->id);	BSON_APPEND_UTF8(bson, "name", dir->name);	BSON_APPEND_UTF8(bson, "parentId", dir->parentId);	return bson;}
开发者ID:GastonTS,项目名称:tp-2015-1c-sachida,代码行数:7,


示例8: mongoc_uri_parse_option

static boolmongoc_uri_parse_option (mongoc_uri_t *uri,                         const char   *str){   int32_t v_int;   const char *end_key;   char *key;   char *value;   if (!(key = scan_to_unichar(str, '=', &end_key))) {      return false;   }   value = bson_strdup(end_key + 1);   mongoc_uri_do_unescape(&value);   if (!strcasecmp(key, "connecttimeoutms") ||       !strcasecmp(key, "sockettimeoutms") ||       !strcasecmp(key, "maxpoolsize") ||       !strcasecmp(key, "minpoolsize") ||       !strcasecmp(key, "maxidletimems") ||       !strcasecmp(key, "waitqueuemultiple") ||       !strcasecmp(key, "waitqueuetimeoutms") ||       !strcasecmp(key, "wtimeoutms")) {      v_int = strtol(value, NULL, 10);      bson_append_int32(&uri->options, key, -1, v_int);   } else if (!strcasecmp(key, "w")) {      if (*value == '-' || isdigit(*value)) {         v_int = strtol (value, NULL, 10);         BSON_APPEND_INT32 (&uri->options, "w", v_int);      } else if (0 == strcasecmp (value, "majority")) {         BSON_APPEND_UTF8 (&uri->options, "w", "majority");      } else if (*value) {         BSON_APPEND_UTF8 (&uri->options, "W", value);      }   } else if (!strcasecmp(key, "canonicalizeHostname") ||              !strcasecmp(key, "journal") ||              !strcasecmp(key, "safe") ||              !strcasecmp(key, "slaveok") ||              !strcasecmp(key, "ssl")) {      bson_append_bool (&uri->options, key, -1,                        (0 == strcasecmp (value, "true")) ||                        (0 == strcasecmp (value, "t")) ||                        (0 == strcmp (value, "1")));   } else if (!strcasecmp(key, "readpreferencetags")) {      mongoc_uri_parse_tags(uri, value, &uri->read_prefs);   } else {      bson_append_utf8(&uri->options, key, -1, value, -1);   }   bson_free(key);   bson_free(value);   return true;}
开发者ID:ChristianHeckl,项目名称:mongo-c-driver,代码行数:55,


示例9: test_find_and_modify_write_concern_wire_32_failure

static voidtest_find_and_modify_write_concern_wire_32_failure (void *context){   mongoc_collection_t *collection;   mongoc_client_t *client;   bson_error_t error;   mongoc_find_and_modify_opts_t *opts;   bson_t reply;   bson_t query = BSON_INITIALIZER;   bson_t *update;   bool success;   mongoc_write_concern_t *wc;   client = test_framework_client_new ();   collection = get_test_collection (client, "writeFailure");   wc = mongoc_write_concern_new ();   mongoc_write_concern_set_w (wc, 42);   mongoc_collection_set_write_concern (collection, wc);   /* Find Zlatan Ibrahimovic, the striker */   BSON_APPEND_UTF8 (&query, "firstname", "Zlatan");   BSON_APPEND_UTF8 (&query, "lastname", "Ibrahimovic");   BSON_APPEND_UTF8 (&query, "profession", "Football player");   BSON_APPEND_INT32 (&query, "age", 34);   BSON_APPEND_INT32 (      &query, "goals", (16 + 35 + 23 + 57 + 16 + 14 + 28 + 84) + (1 + 6 + 62));   /* Add his football position */   update = BCON_NEW ("$set", "{", "position", BCON_UTF8 ("striker"), "}");   opts = mongoc_find_and_modify_opts_new ();   mongoc_find_and_modify_opts_set_update (opts, update);   /* Create the document if it didn't exist, and return the updated document */   mongoc_find_and_modify_opts_set_flags (      opts, MONGOC_FIND_AND_MODIFY_UPSERT | MONGOC_FIND_AND_MODIFY_RETURN_NEW);   success = mongoc_collection_find_and_modify_with_opts (      collection, &query, opts, &reply, &error);   ASSERT (!success);   ASSERT_ERROR_CONTAINS (      error, MONGOC_ERROR_WRITE_CONCERN, 100, "Write Concern error:");   bson_destroy (&reply);   bson_destroy (update);   bson_destroy (&query);   mongoc_find_and_modify_opts_destroy (opts);   mongoc_collection_drop (collection, NULL);   mongoc_collection_destroy (collection);   mongoc_client_destroy (client);}
开发者ID:rcsanchez97,项目名称:mongo-c-driver,代码行数:54,


示例10: bson_new

void SettingsOutput::SetSubbasinIDs(){	bson_t *b = bson_new();	bson_t *child = bson_new();	bson_t *child2 = bson_new();	bson_t *child3 = bson_new();	BSON_APPEND_DOCUMENT_BEGIN(b, "$query", child);	BSON_APPEND_DOCUMENT_BEGIN(child, PARAM_FLD_NAME, child2);	BSON_APPEND_ARRAY_BEGIN(child2, "$in", child3);	BSON_APPEND_UTF8(child3,PARAM_FLD_NAME, VAR_OUTLETID);	BSON_APPEND_UTF8(child3,PARAM_FLD_NAME, VAR_SUBBSNID_NUM);	bson_append_array_end(child2, child3);	bson_append_document_end(child, child2);	bson_append_document_end(b, child);	//printf("%s/n",bson_as_json(b,NULL));	mongoc_cursor_t *cursor;	const bson_t *bsonTable;	mongoc_collection_t *collection;	collection = mongoc_client_get_collection(m_conn, m_dbName.c_str(), DB_TAB_PARAMETERS);	cursor = mongoc_collection_find(collection, MONGOC_QUERY_NONE, 0, 0, 0, b, NULL, NULL);	bson_iter_t iter;	while (mongoc_cursor_more(cursor) && mongoc_cursor_next(cursor, &bsonTable))	{		string nameTmp = "";		int numTmp = -1;		if (bson_iter_init_find(&iter, bsonTable, PARAM_FLD_NAME))			nameTmp = GetStringFromBSONITER(&iter);		if (bson_iter_init_find(&iter, bsonTable, PARAM_FLD_VALUE))			numTmp = GetIntFromBSONITER(&iter);		if(!StringMatch(nameTmp, "") && numTmp != -1)		{			if(StringMatch(nameTmp, VAR_OUTLETID))				m_outletID = GetIntFromBSONITER(&iter);			else if (StringMatch(nameTmp, VAR_SUBBSNID_NUM))				m_nSubbasins = GetIntFromBSONITER(&iter);		}		else			throw ModelException("SettingOutput","SetSubbasinIDs","No valid values found in MongoDB!");	}	bson_destroy(child);	bson_destroy(child2);	bson_destroy(child3);	bson_destroy(b);	mongoc_collection_destroy(collection);	mongoc_cursor_destroy(cursor);	return;}
开发者ID:gaohr,项目名称:SEIMS,代码行数:50,


示例11: collection_drop

static future_t *collection_drop (func_ctx_t *ctx, bson_t *cmd){   BSON_APPEND_UTF8 (cmd, "drop", "collection");   return future_collection_drop_with_opts (      ctx->collection, ctx->opts, &ctx->error);}
开发者ID:acmorrow,项目名称:mongo-c-driver,代码行数:7,


示例12: estimated_document_count

static future_t *estimated_document_count (func_ctx_t *ctx, bson_t *cmd){   BSON_APPEND_UTF8 (cmd, "count", "collection");   return future_collection_estimated_document_count (      ctx->collection, ctx->opts, ctx->prefs, NULL, &ctx->error);}
开发者ID:acmorrow,项目名称:mongo-c-driver,代码行数:7,


示例13: drop_index

static future_t *drop_index (func_ctx_t *ctx, bson_t *cmd){   BSON_APPEND_UTF8 (cmd, "dropIndexes", "collection");   return future_collection_drop_index_with_opts (      ctx->collection, "index name", ctx->opts, &ctx->error);}
开发者ID:acmorrow,项目名称:mongo-c-driver,代码行数:7,


示例14: create_index

static future_t *create_index (func_ctx_t *ctx, bson_t *cmd){   BSON_APPEND_UTF8 (cmd, "createIndexes", "collection");   return future_collection_create_index_with_opts (      ctx->collection, tmp_bson ("{}"), NULL, ctx->opts, NULL, &ctx->error);}
开发者ID:acmorrow,项目名称:mongo-c-driver,代码行数:7,


示例15: db_write_cmd

static future_t *db_write_cmd (func_ctx_t *ctx, bson_t *cmd){   BSON_APPEND_UTF8 (cmd, "foo", "db");   return future_database_write_command_with_opts (      ctx->db, tmp_bson ("{'foo': 'db'}"), ctx->opts, NULL, &ctx->error);}
开发者ID:acmorrow,项目名称:mongo-c-driver,代码行数:7,


示例16: mongo_del_origin

static int mongo_del_origin(u08bits *origin){  mongoc_collection_t * collection = mongo_get_collection("realm");   if(!collection)    return -1;      int ret = -1;    bson_t query, doc, child;  bson_init(&query);  bson_init(&doc);  bson_append_document_begin(&doc, "$pull", -1, &child);  BSON_APPEND_UTF8(&child, "origin", (const char *)origin);  bson_append_document_end(&doc, &child);  if (!mongoc_collection_update(collection, MONGOC_UPDATE_MULTI_UPDATE, &query, &doc, NULL, NULL)) {    TURN_LOG_FUNC(TURN_LOG_LEVEL_ERROR, "Error deleting origin information/n");  } else {    ret = 0;  }  mongoc_collection_destroy(collection);  bson_destroy(&query);  bson_destroy(&doc);  return ret;}
开发者ID:SteppeChange,项目名称:coturn,代码行数:26,


示例17: bulk_insert

static boolbulk_insert (mongoc_bulk_operation_t *bulk, bson_error_t *error, bson_t *cmd){   BSON_APPEND_UTF8 (cmd, "insert", "collection");   return mongoc_bulk_operation_insert_with_opts (      bulk, tmp_bson ("{}"), NULL, error);}
开发者ID:acmorrow,项目名称:mongo-c-driver,代码行数:7,


示例18: sim_parser_connect_test1

/* Check a correct CONNECT message */static gbooleansim_parser_connect_test1 (void){  bson_t *bson_connect = bson_new ();  bson_t child;  uint8_t uuid[]={0x07,0x92,0xd6,0x72,0xf4,0xce,0x11,0xe4,0x9d,0xe2,0x00,0x0c,0x29,0xd9,0x46,0xde};  SimParser *parser = NULL;  SimCommand *cmd = NULL;  gboolean result = FALSE;  bson_append_document_begin (bson_connect,"connect", -1, &child);  BSON_APPEND_INT32 (&child, "id", 10);  BSON_APPEND_INT32 (&child, "type", SIM_SESSION_TYPE_WEB);  BSON_APPEND_UTF8 (&child, "version", "5.0.1");  if (bson_append_binary (&child, "sensor_id", -1, BSON_SUBTYPE_UUID, uuid, 16) == FALSE)    return FALSE;  bson_append_document_end (bson_connect, &child);  /* Check */  bson_iter_t iter;  bson_iter_init (&iter, bson_connect);  do{    if ((parser = sim_parser_new()) == NULL)    {       result = FALSE;      break;    }    if ((cmd = sim_parser_bson (parser, bson_get_data (bson_connect), bson_connect->len)) == NULL)    {      result = FALSE;      break;    }    if (cmd->type !=  SIM_COMMAND_TYPE_CONNECT)    {      result = FALSE;      break;    }    if (cmd->data.connect.sensor_ver->major != 5 || cmd->data.connect.sensor_ver->minor != 0 || cmd->data.connect.sensor_ver->micro != 1)    {      result = FALSE;      break;    }    if (cmd->data.connect.sensor_id == NULL)    {      result = FALSE;      break;    }    /* Check uuid */    SimUuid * uuidbin =  sim_uuid_new_from_bin (uuid);    gboolean test =  sim_uuid_equal (uuidbin, cmd->data.connect.sensor_id);    g_object_unref (uuidbin);    if (!test)    {      result = FALSE;      break;    }    result = TRUE;  } while (0);  bson_destroy (bson_connect);  g_object_unref (parser);  return result;}
开发者ID:jackpf,项目名称:ossim-arc,代码行数:61,


示例19: mongodb_module_process

int mongodb_module_process(fieldset_t *fs){	bson_t *doc;	if (!bulk) {		return EXIT_FAILURE;	}	if (buffer_fill == BUFFER_SIZE) {		if (mongodb_module_flush()) {			return EXIT_FAILURE;		}	}	doc = bson_new();	for (int i=0; i < fs->len; i++) {		field_t *f = &(fs->fields[i]);		if (f->type == FS_STRING) {			BSON_APPEND_UTF8(doc,f->name,f->value.ptr);		} else if (f->type == FS_UINT64) {			BSON_APPEND_INT64(doc,f->name,(uint64_t) f->value.num);		} else if (f->type == FS_BINARY) {			BSON_APPEND_BINARY(doc,f->name, BSON_SUBTYPE_BINARY,f->value.ptr, f->len);		} else if (f->type == FS_NULL) {			// do nothing		} else {			log_fatal("mongodb", "received unknown output type");		}	}	mongoc_bulk_operation_insert(bulk,doc);	buffer_fill++;	return EXIT_SUCCESS;}
开发者ID:Fale,项目名称:zmap,代码行数:33,


示例20: sim_parser_connect_test2

/* check a  missing mandatory fix */static gbooleansim_parser_connect_test2 (void){  bson_t *bson_connect = bson_new ();  bson_t child;  SimParser *parser = NULL;  SimCommand *cmd = NULL;  gboolean result = FALSE;  bson_append_document_begin (bson_connect,"connect", -1, &child);  BSON_APPEND_INT32 (&child, "id", 10);  BSON_APPEND_INT32 (&child, "type", SIM_SESSION_TYPE_WEB);  BSON_APPEND_UTF8 (&child, "version", "5.0.1");  bson_append_document_end (bson_connect, &child);  do{    if ((parser = sim_parser_new()) == NULL)    {       result = FALSE;      break;    }    if ((cmd = sim_parser_bson (parser, bson_get_data (bson_connect), bson_connect->len)) != NULL)    {      result = FALSE;      break;    }    result = TRUE;  } while (0);  return result;}
开发者ID:jackpf,项目名称:ossim-arc,代码行数:30,


示例21: delete_many

static future_t *delete_many (func_ctx_t *ctx, bson_t *cmd){   BSON_APPEND_UTF8 (cmd, "delete", "collection");   BSON_ASSERT (!ctx->prefs);   return future_collection_delete_many (      ctx->collection, tmp_bson ("{}"), ctx->opts, NULL, &ctx->error);}
开发者ID:acmorrow,项目名称:mongo-c-driver,代码行数:8,


示例22: insert_one

static future_t *insert_one (func_ctx_t *ctx, bson_t *cmd){   BSON_APPEND_UTF8 (cmd, "insert", "collection");   BSON_ASSERT (!ctx->prefs);   return future_collection_insert_one (      ctx->collection, tmp_bson ("{}"), ctx->opts, NULL, &ctx->error);}
开发者ID:acmorrow,项目名称:mongo-c-driver,代码行数:8,


示例23: fam_flags

void fam_flags(mongoc_collection_t *collection){   mongoc_find_and_modify_opts_t *opts;   bson_t reply;   bson_error_t error;   bson_t query = BSON_INITIALIZER;   bson_t *update;   bool success;   /* Find Zlatan Ibrahimovic, the striker */   BSON_APPEND_UTF8 (&query, "firstname", "Zlatan");   BSON_APPEND_UTF8 (&query, "lastname", "Ibrahimovic");   BSON_APPEND_UTF8 (&query, "profession", "Football player");   BSON_APPEND_INT32 (&query, "age", 34);   BSON_APPEND_INT32 (&query, "goals", (16+35+23+57+16+14+28+84)+(1+6+62));   /* Add his football position */   update = BCON_NEW ("$set", "{",      "position", BCON_UTF8 ("striker"),   "}");   opts = mongoc_find_and_modify_opts_new ();   mongoc_find_and_modify_opts_set_update (opts, update);   /* Create the document if it didn't exist, and return the updated document */   mongoc_find_and_modify_opts_set_flags (opts, MONGOC_FIND_AND_MODIFY_UPSERT|MONGOC_FIND_AND_MODIFY_RETURN_NEW);   success = mongoc_collection_find_and_modify_with_opts (collection, &query, opts, &reply, &error);   if (success) {      char *str;      str = bson_as_json (&reply, NULL);      printf ("%s/n", str);      bson_free (str);   } else {      fprintf(stderr, "Got error: /"%s/" on line %d/n", error.message, __LINE__);   }   bson_destroy (&reply);   bson_destroy (update);   bson_destroy (&query);   mongoc_find_and_modify_opts_destroy (opts);}
开发者ID:AbhimanyuAryan,项目名称:treefrog-framework,代码行数:46,


示例24: main

int main (int argc, char *argv[]){    mongoc_client_t *client;    mongoc_collection_t *collection;    bson_error_t error;    bson_oid_t oid;    bson_t *doc;    /* Init mongo C driver */    mongoc_init ();    /* Create a new connection to the database a get the specified collection  */    client = mongoc_client_new ("mongodb://localhost:27017/");    if (!client) {        fprintf(stderr, "Connection to database failed!");        mongoc_cleanup();        return 0;    } else {        printf("Connected to the database successfully/n");    }    collection = mongoc_client_get_collection (client, "testdb", "users");    /* Create a new document (All the documents must have the _id field to be used as primary key) */    doc = bson_new ();    bson_oid_init (&oid, NULL);    BSON_APPEND_OID (doc, "_id", &oid);    BSON_APPEND_UTF8 (doc, "username", "John");    BSON_APPEND_UTF8 (doc, "password", "123456");    /* Insert the document into the collection */    if (!mongoc_collection_insert (collection, MONGOC_INSERT_NONE, doc, NULL, &error)) {        printf ("Error inserting the document. - %s/n", error.message);    } else {        printf ("Document successfully inserted!/n");    }    /* Clean the doc, colletion and client allocations */    bson_destroy (doc);    mongoc_collection_destroy (collection);    mongoc_client_destroy (client);    /* Cleanup after mongo C driver */    mongoc_cleanup();    return 0;}
开发者ID:rollbackpt,项目名称:c_databases_examples,代码行数:46,


示例25: mongo_set_permission_ip

static int mongo_set_permission_ip(const char *kind, u08bits *realm, const char* ip, int del){	char sub_collection_name[129];	snprintf(sub_collection_name,sizeof(sub_collection_name)-1,"%s_peer_ip",kind);	mongoc_collection_t * collection = mongo_get_collection("realm");	if(!collection)		return -1;	int ret = -1;	u08bits realm0[STUN_MAX_REALM_SIZE+1] = "/0";	if(!realm) realm=realm0;	bson_t query, doc, child;	bson_init(&query);	BSON_APPEND_UTF8(&query, "realm", (const char *)realm);	bson_init(&doc);	if(del) {		bson_append_document_begin(&doc, "$pull", -1, &child);	} else {		bson_append_document_begin(&doc, "$addToSet", -1, &child);	}	BSON_APPEND_UTF8(&child, sub_collection_name, (const char *)ip);	bson_append_document_end(&doc, &child);	mongoc_update_flags_t flags = MONGOC_UPDATE_NONE;	if(del) {		flags = MONGOC_UPDATE_MULTI_UPDATE;	} else {		flags = MONGOC_UPDATE_UPSERT;	}	if (!mongoc_collection_update(collection, flags, &query, &doc, NULL, NULL)) {		TURN_LOG_FUNC(TURN_LOG_LEVEL_ERROR, "Error inserting permission ip information/n");	} else {		ret = 0;	}	mongoc_collection_destroy(collection);	bson_destroy(&query);	bson_destroy(&doc);	return ret;}
开发者ID:SteppeChange,项目名称:coturn,代码行数:45,


示例26: saveAlarmLog

static void saveAlarmLog(mongoc_collection_t *coll,char* se_id,int code,char * tel,char * msg,char* userId,char * device_name,char* name,char * de_id){     bson_t *sdoc = bson_new ();     bson_oid_t a_oid;     bson_oid_init (&a_oid, NULL);     BSON_APPEND_OID (sdoc, "_id", &a_oid);     //BSON_APPEND_OID (sdoc, "device_id", de_oid);     //BSON_APPEND_UTF8 (sdoc, "name", name);     //BSON_APPEND_INT32 (sdoc, "sensorType", sensorType);     BSON_APPEND_INT32 (sdoc, "code", code);     BSON_APPEND_UTF8 (sdoc, "mobile", tel);     BSON_APPEND_UTF8 (sdoc, "sendmsg", msg);     BSON_APPEND_UTF8 (sdoc, "user_id", userId);     BSON_APPEND_UTF8 (sdoc, "se_id", se_id);     BSON_APPEND_UTF8 (sdoc, "de_id", de_id);     BSON_APPEND_UTF8 (sdoc, "device_name", device_name);     BSON_APPEND_UTF8 (sdoc, "sensor_name", name);     time_t timep;     time(&timep);     BSON_APPEND_DOUBLE (sdoc, "time", timep);     bson_error_t serror;     if (!mongoc_collection_insert (coll, MONGOC_INSERT_NONE, sdoc, NULL, &serror)) {        fprintf (stderr, "%s/n", serror.message);     }     bson_destroy (sdoc);}
开发者ID:bjut2011,项目名称:smartIOT,代码行数:25,


示例27: bulk_update_one

static boolbulk_update_one (mongoc_bulk_operation_t *bulk,                 bson_error_t *error,                 bson_t *cmd){   BSON_APPEND_UTF8 (cmd, "update", "collection");   return mongoc_bulk_operation_update_one_with_opts (      bulk, tmp_bson ("{}"), tmp_bson ("{}"), NULL, error);}
开发者ID:acmorrow,项目名称:mongo-c-driver,代码行数:9,


示例28: test_large_return

static voidtest_large_return (void){   mongoc_collection_t *collection;   mongoc_client_t *client;   mongoc_cursor_t *cursor;   bson_error_t error;   const bson_t *doc = NULL;   bson_oid_t oid;   bson_t insert_doc = BSON_INITIALIZER;   bson_t query = BSON_INITIALIZER;   size_t len;   char *str;   bool r;   client = mongoc_client_new (gTestUri);   ASSERT (client);   collection = get_test_collection (client, "test_large_return");   ASSERT (collection);   len = 1024 * 1024 * 4;   str = bson_malloc (len);   memset (str, (int)' ', len);   str [len - 1] = '/0';   bson_oid_init (&oid, NULL);   BSON_APPEND_OID (&insert_doc, "_id", &oid);   BSON_APPEND_UTF8 (&insert_doc, "big", str);   r = mongoc_collection_insert (collection, MONGOC_INSERT_NONE, &insert_doc, NULL, &error);   assert (r);   bson_destroy (&insert_doc);   BSON_APPEND_OID (&query, "_id", &oid);   cursor = mongoc_collection_find (collection, MONGOC_QUERY_NONE, 0, 0, 0, &query, NULL, NULL);   assert (cursor);   bson_destroy (&query);   r = mongoc_cursor_next (cursor, &doc);   assert (r);   assert (doc);   r = mongoc_cursor_next (cursor, &doc);   assert (!r);   mongoc_cursor_destroy (cursor);   r = mongoc_collection_drop (collection, &error);   assert (r);   mongoc_collection_destroy (collection);   mongoc_client_destroy (client);   bson_free (str);}
开发者ID:Convey-Compliance,项目名称:mongo-c-driver,代码行数:57,



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


C++ BSON_ITER_HOLDS_INT32函数代码示例
C++ BSON_APPEND_INT32函数代码示例
万事OK自学网:51自学网_软件自学网_CAD自学网自学excel、自学PS、自学CAD、自学C语言、自学css3实例,是一个通过网络自主学习工作技能的自学平台,网友喜欢的软件自学网站。