gpt4 book ai didi

c - mongodb c-api 中的 $exists 查询

转载 作者:行者123 更新时间:2023-11-30 15:48:11 25 4
gpt4 key购买 nike

我正在尝试用 C 实现以下 mongodb 查询

db.test.find({"timestamp": {"$exists":true}});

我以为会是这样的

bson query, existspart;
mongo_cursor cursor;
int i;

bson_init(&existspart);
bson_append_string ( &existspart, "$exists", "false" );
bson_finish(&existspart);
bson_init(&query);
bson_append_bson ( &query, "timestamp", &existspart );
bson_finish(&query);

mongo_cursor_init(&cursor, conn, "mydb.test");
mongo_cursor_set_query(&cursor, &query );
while( mongo_cursor_next( &cursor ) == MONGO_OK )
{
// blabla
}

但是它不起作用。我做错了什么?

最佳答案

替换

bson_append_string ( &existspart, "$exists", "false" );

bson_append_bool ( &existspart, "$exists", 1 );

bson_append_bool ( &existspart, "$exists", 0 );

如果您不希望该字段存在

关于c - mongodb c-api 中的 $exists 查询,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16915273/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com