我正在尝试在 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
}
但它不起作用。我做错了什么?