Skip to content

Commit 2039d72

Browse files
committed
Support for cursors in crud metadata
1 parent 4329555 commit 2039d72

21 files changed

+648
-361
lines changed

build/autotools/versions.ldscript

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -219,13 +219,14 @@ LIBMONGOC_1.0 {
219219

220220
LIBMONGOC_1.1 {
221221
global:
222+
mongoc_client_get_database_info;
222223
mongoc_collection_count_with_opts;
223224
mongoc_collection_get_index_info;
224225
mongoc_database_get_collection_info;
225226
mongoc_index_opt_geo_get_default;
226227
mongoc_index_opt_geo_init;
227-
mongoc_rand_seed;
228228
mongoc_rand_add;
229+
mongoc_rand_seed;
229230
mongoc_rand_status;
230231
mongoc_uri_get_credentials;
231232
mongoc_uri_get_mechanism_properties;

build/cmake/libmongoc-ssl.def

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ mongoc_client_command_simple
2121
mongoc_client_destroy
2222
mongoc_client_get_collection
2323
mongoc_client_get_database
24+
mongoc_client_get_database_info
2425
mongoc_client_get_database_names
2526
mongoc_client_get_gridfs
2627
mongoc_client_get_max_bson_size

build/cmake/libmongoc.def

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ mongoc_client_command_simple
2121
mongoc_client_destroy
2222
mongoc_client_get_collection
2323
mongoc_client_get_database
24+
mongoc_client_get_database_info
2425
mongoc_client_get_database_names
2526
mongoc_client_get_gridfs
2627
mongoc_client_get_max_bson_size

src/libmongoc.symbols

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ mongoc_client_command_simple
2020
mongoc_client_destroy
2121
mongoc_client_get_collection
2222
mongoc_client_get_database
23+
mongoc_client_get_database_info
2324
mongoc_client_get_database_names
2425
mongoc_client_get_gridfs
2526
mongoc_client_get_max_bson_size

src/mongoc/Makefile.am

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ INST_H_FILES = \
3232
src/mongoc/mongoc-counters-private.h \
3333
src/mongoc/mongoc-cursor-array-private.h \
3434
src/mongoc/mongoc-cursor-cursorid-private.h \
35+
src/mongoc/mongoc-cursor-transform-private.h \
3536
src/mongoc/mongoc-cursor-private.h \
3637
src/mongoc/mongoc-cursor.h \
3738
src/mongoc/mongoc-database-private.h \
@@ -102,6 +103,7 @@ MONGOC_SOURCES_SHARED += \
102103
src/mongoc/mongoc-cursor.c \
103104
src/mongoc/mongoc-cursor-array.c \
104105
src/mongoc/mongoc-cursor-cursorid.c \
106+
src/mongoc/mongoc-cursor-transform.c \
105107
src/mongoc/mongoc-database.c \
106108
src/mongoc/mongoc-init.c \
107109
src/mongoc/mongoc-gridfs.c \

src/mongoc/mongoc-client.c

Lines changed: 34 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
# include <netinet/tcp.h>
2222
#endif
2323

24+
#include "mongoc-cursor-array-private.h"
2425
#include "mongoc-client.h"
2526
#include "mongoc-client-private.h"
2627
#include "mongoc-cluster-private.h"
@@ -1287,52 +1288,63 @@ mongoc_client_get_database_names (mongoc_client_t *client,
12871288
bson_error_t *error)
12881289
{
12891290
bson_iter_t iter;
1290-
bson_iter_t child;
1291-
bson_iter_t child2;
12921291
const char *name;
12931292
bson_t cmd = BSON_INITIALIZER;
1294-
bson_t reply;
12951293
char **ret = NULL;
12961294
int i = 0;
1295+
mongoc_cursor_t *cursor;
1296+
const bson_t *doc;
12971297

12981298
BSON_ASSERT (client);
12991299

1300-
BSON_APPEND_INT32 (&cmd, "listDatabases", 1);
1301-
1302-
if (!mongoc_client_command_simple (client, "admin", &cmd, NULL,
1303-
&reply, error)) {
1304-
bson_destroy (&cmd);
1305-
return NULL;
1306-
}
1300+
cursor = mongoc_client_get_database_info (client, error);
13071301

1308-
if (bson_iter_init_find (&iter, &reply, "databases") &&
1309-
BSON_ITER_HOLDS_ARRAY (&iter) &&
1310-
bson_iter_recurse (&iter, &child)) {
1311-
while (bson_iter_next (&child)) {
1312-
if (BSON_ITER_HOLDS_DOCUMENT (&child) &&
1313-
bson_iter_recurse (&child, &child2) &&
1314-
bson_iter_find (&child2, "name") &&
1315-
BSON_ITER_HOLDS_UTF8 (&child2) &&
1316-
(name = bson_iter_utf8 (&child2, NULL)) &&
1317-
(0 != strcmp (name, "local"))) {
1302+
while (mongoc_cursor_next (cursor, &doc)) {
1303+
if (bson_iter_init (&iter, doc) &&
1304+
bson_iter_find (&iter, "name") &&
1305+
BSON_ITER_HOLDS_UTF8 (&iter) &&
1306+
(name = bson_iter_utf8 (&iter, NULL)) &&
1307+
(0 != strcmp (name, "local"))) {
13181308
ret = bson_realloc (ret, sizeof(char*) * (i + 2));
13191309
ret [i] = bson_strdup (name);
13201310
ret [++i] = NULL;
13211311
}
1322-
}
13231312
}
13241313

13251314
if (!ret) {
13261315
ret = bson_malloc0 (sizeof (void*));
13271316
}
13281317

13291318
bson_destroy (&cmd);
1330-
bson_destroy (&reply);
13311319

13321320
return ret;
13331321
}
13341322

13351323

1324+
mongoc_cursor_t *
1325+
mongoc_client_get_database_info (mongoc_client_t *client,
1326+
bson_error_t *error)
1327+
{
1328+
bson_t cmd = BSON_INITIALIZER;
1329+
mongoc_cursor_t *cursor;
1330+
1331+
BSON_ASSERT (client);
1332+
1333+
BSON_APPEND_INT32 (&cmd, "listDatabases", 1);
1334+
1335+
cursor = mongoc_client_command (client, "admin", MONGOC_QUERY_SLAVE_OK, 0, 0, 0,
1336+
&cmd, NULL, NULL);
1337+
1338+
_mongoc_cursor_array_init(cursor, "databases");
1339+
1340+
cursor->limit = 0;
1341+
1342+
bson_destroy (&cmd);
1343+
1344+
return cursor;
1345+
}
1346+
1347+
13361348
int32_t
13371349
mongoc_client_get_max_message_size (mongoc_client_t *client) /* IN */
13381350
{

src/mongoc/mongoc-client.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,8 @@ mongoc_collection_t *mongoc_client_get_collection (mongoc_client
112112
const char *collection);
113113
char **mongoc_client_get_database_names (mongoc_client_t *client,
114114
bson_error_t *error);
115+
mongoc_cursor_t *mongoc_client_get_database_info (mongoc_client_t *client,
116+
bson_error_t *error);
115117
bool mongoc_client_get_server_status (mongoc_client_t *client,
116118
mongoc_read_prefs_t *read_prefs,
117119
bson_t *reply,

src/mongoc/mongoc-collection-private.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ mongoc_collection_t *_mongoc_collection_new (mongoc_client_t
5050
const char *collection,
5151
const mongoc_read_prefs_t *read_prefs,
5252
const mongoc_write_concern_t *write_concern);
53-
bson_t *_mongoc_collection_get_index_info_legacy (mongoc_collection_t *collection,
53+
mongoc_cursor_t *_mongoc_collection_get_index_info_legacy (mongoc_collection_t *collection,
5454
bson_error_t *error);
5555

5656

0 commit comments

Comments
 (0)