mongoc_collection_count
发布日期:2021-06-30 22:15:17 浏览次数:2 分类:技术文章

本文共 1553 字,大约阅读时间需要 5 分钟。

前言

按照mongoc说明书, 做个mongoc_collection_count试验.

返回类型PRId64很大啊, 例子中格式化成字符串不好使, 只能先按longlong用了.

记录

int testcase_mongoc_example_document_query_special_count(int argc, char* argv[]){    mongoc_client_t* client = NULL;    mongoc_collection_t* collection = NULL;    const bson_t* doc = NULL;    bson_t* query = NULL;    bson_t child = BSON_INITIALIZER;    long lIndex = 0;    char szBuf[260] = {
'\0'}; int64_t count = 0; bson_error_t error = {
0}; char *uri_str = NULL; mongoc_init(); client = mongoc_client_new( "mongodb://localhost:27017/?appname=find-specific-example"); collection = mongoc_client_get_collection(client, "db_ls", "coll_ls"); query = bson_new(); // find db record set name : {first:x, last:cn} bson_append_document_begin(query, "name", -1, &child); BSON_APPEND_UTF8(&child, "first", "lostspeed258"); BSON_APPEND_UTF8(&child, "last", "hk"); bson_append_document_end(query, &child); count = mongoc_collection_count(collection, MONGOC_QUERY_NONE, query, 0, 0, NULL, &error); if (count < 0) { ShowErrMsg("mongoc_collection_count", &error); } else { // PRId64不好使啊, 是不是版本高才好使啊? // 就按照long long 使用吧 uri_str = bson_strdup_printf("mongoc_collection_count = 0x%x\n", (long long)count); printf("%s", uri_str); /** run result mongoc_collection_count = 0x1 */ } bson_free (uri_str); bson_destroy(query); mongoc_collection_destroy(collection); mongoc_client_destroy(client); mongoc_cleanup(); return 0;}

转载地址:https://lostspeed.blog.csdn.net/article/details/69218504 如侵犯您的版权,请留言回复原文章的地址,我们会给您删除此文章,给您带来不便请您谅解!

上一篇:mongoc create index
下一篇:del mongo document by _id

发表评论

最新留言

留言是一种美德,欢迎回访!
[***.207.175.100]2024年04月14日 07时18分08秒