我正在尝试进行查询,该查询必须从我的 mongodb 数据库中检索一些数据,请按照我的代码:
72 mongo conn[1];
73 mongo_cursor cursor[1];
74
75 //Parameters (connection, IP, port);
76 int status = mongo_connect(conn, "127.0.0.1", 27017);
77 if(status != MONGO_OK){
78 switch(conn->err){
79 case MONGO_CONN_NO_SOCKET: printf("Socket not found\n"); return 1;
80 case MONGO_CONN_FAIL: printf("Connection Failed\n"); return 1;
81 case MONGO_CONN_NOT_MASTER: printf("Not master\n"); return 1;
82 }
83 }
84
85 //add_new_service(conn, 55, 75,"java","7");
86 bson query[1];
87 bson_init(query);
88 bson_append_start_object(query, "$query");
89 bson_append_int(query,"cpu",75);
90 bson_append_finish_object(query);
91 bson_finish(query);
92
93 bson fields[1];
94 bson_init(fields);
95 bson_append_null(fields,"machine");
96 bson_finish(fields);
97
98 mongo_cursor_init(cursor, conn, "db.services");
99
100 cursor = mongo_find(conn,"db.services", query, fields, 9999, 0, 0);
101
102 while(mongo_cursor_next(ptr_cursor) == MONGO_OK){
103 bson_print(&ptr_cursor->current);
104 }
105
106 mongo_cursor_destroy(cursor);
107 mongo_destroy(conn);
108 return 0;
我不知道如何使用方法“mongo_find”(第 100 行),它返回一个指向 mongo_cursor 的指针,但我无法操纵这个指针,有一些想法可以帮助我实现这一目标吗?