#include// Open a connection to the "mydb" database WT_CONNECTION *conn; wt_conn_open("file:mydb", NULL, "create", &conn); // Open a cursor on the "mytable" collection WT_CURSOR *cur; conn->open_cursor(conn, "mytable", NULL, NULL, &cur); // Iterate through all the key-value pairs and print them while (cur->next(cur) == 0) { WT_ITEM key, value; cur->get_key(cur, &key); cur->get_value(cur, &value); printf("Key: %.*s, Value: %.*s\n", (int)key.size, key.data, (int)value.size, value.data); } // Close the cursor and the database connection cur->close(cur); conn->close(conn, NULL);
#includeIn this example, WT_CURSOR next is not used directly, but the set_key function is used to seek to a specific key ("foo"), and then the get_value function is used to retrieve its value. Both of these examples use the WiredTiger C API, which is designed for C and C++ developers. Therefore, the package library for WT_CURSOR next is the WiredTiger library, which is generally installed as a system library on Linux systems.// Open a connection to the "mydb" database WT_CONNECTION *conn; wt_conn_open("file:mydb", NULL, "create", &conn); // Open a cursor on the "mytable" collection WT_CURSOR *cur; conn->open_cursor(conn, "mytable", NULL, NULL, &cur); // Seek to the key "foo" and print its value WT_ITEM key = { .data = "foo", .size = 3 }; if (cur->set_key(cur, &key) == 0 && cur->get_value(cur, &value) == 0) { printf("Value: %.*s\n", (int)value.size, value.data); } // Close the cursor and the database connection cur->close(cur); conn->close(conn, NULL);