void mongoc_gridfs_destroy (mongoc_gridfs_t *gridfs) { ENTRY; BSON_ASSERT (gridfs); mongoc_collection_destroy (gridfs->files); mongoc_collection_destroy (gridfs->chunks); bson_free (gridfs); EXIT; }
static int mongo_set_admin_user(const u08bits *usname, const u08bits *realm, const password_t pwd) { mongoc_collection_t * collection = mongo_get_collection("admin_user"); if(!collection) return -1; bson_t query; bson_init(&query); BSON_APPEND_UTF8(&query, "name", (const char *)usname); bson_t doc; bson_init(&doc); BSON_APPEND_UTF8(&doc, "name", (const char *)usname); BSON_APPEND_UTF8(&doc, "realm", (const char *)realm); BSON_APPEND_UTF8(&doc, "password", (const char *)pwd); int ret = -1; if (!mongoc_collection_update(collection, MONGOC_UPDATE_UPSERT, &query, &doc, NULL, NULL)) { TURN_LOG_FUNC(TURN_LOG_LEVEL_ERROR, "Error inserting/updating admin user information\n"); } else { ret = 0; } mongoc_collection_destroy(collection); bson_destroy(&doc); bson_destroy(&query); return ret; }
/* * Retrieve result set */ static int db_mongodb_store_result(const db1_con_t* _h, db1_res_t** _r) { km_mongodb_con_t *mgcon; db_mongodb_result_t *mgres; const bson_t *itdoc; mgcon = MONGODB_CON(_h); if(!_r) { LM_ERR("invalid result parameter\n"); return -1; } *_r = db_mongodb_new_result(); if (!*_r) { LM_ERR("no memory left for result \n"); goto error; } mgres = (db_mongodb_result_t*)RES_PTR(*_r); mgres->collection = mgcon->collection; mgcon->collection = NULL; mgres->cursor = mgcon->cursor; mgcon->cursor = NULL; mgres->colsdoc = mgcon->colsdoc; mgcon->colsdoc = NULL; mgres->nrcols = mgcon->nrcols; mgcon->nrcols = 0; if(!mongoc_cursor_more (mgres->cursor) || !mongoc_cursor_next (mgres->cursor, &itdoc) || !itdoc) { LM_DBG("no result from mongodb\n"); return 0; } /* first document linked internally in result to get columns */ mgres->rdoc = (bson_t*)itdoc; if(db_mongodb_get_columns(_h, *_r)<0) { LM_ERR("failed to set the columns\n"); goto error; } if(db_mongodb_convert_result(_h, *_r)<0) { LM_ERR("failed to set the rows in result\n"); goto error; } return 0; error: if(mgcon->colsdoc) { bson_destroy (mgcon->colsdoc); mgcon->colsdoc = NULL; } mgcon->nrcols = 0; if(mgcon->cursor) { mongoc_cursor_destroy (mgcon->cursor); mgcon->cursor = NULL; } if(mgcon->collection) { mongoc_collection_destroy (mgcon->collection); mgcon->collection = NULL; } return -1; }
bool TMongoDriver::find(const QString &collection, const QVariantMap &criteria, const QVariantMap &orderBy, const QStringList &fields, int limit, int skip, int ) { if (!isOpen()) { return false; } errorCode = 0; errorString.clear(); mongoc_collection_t *col = mongoc_client_get_collection(mongoClient, qPrintable(dbName), qPrintable(collection)); mongoc_cursor_t *cursor = mongoc_collection_find(col, MONGOC_QUERY_NONE, skip, limit, 0, (bson_t *)TBson::toBson(criteria, orderBy).data(), (bson_t *)TBson::toBson(fields).data(), nullptr); /* Read Prefs, nullptr for default */ setLastCommandStatus(mongoc_collection_get_last_error(col)); mongoc_collection_destroy(col); mongoCursor->setCursor(cursor); if (cursor) { bson_error_t error; if (mongoc_cursor_error(cursor, &error)) { errorCode = error.code; errorString = QLatin1String(error.message); } } else { tSystemError("MongoDB Cursor Error"); } return (bool)cursor; }
int main(void) { mongoc_collection_t *collection; mongoc_database_t *database; mongoc_client_t *client; bson_error_t error; bson_t *options; client = mongoc_client_new ("mongodb://localhost:27017/admin"); database = mongoc_client_get_database (client, "databaseName"); options = BCON_NEW ( "validator", "{", "age", "{", "$lte", BCON_INT32 (34), "}", "}", "validationAction", BCON_UTF8 ("error"), "validationLevel", BCON_UTF8 ("moderate")); collection = mongoc_database_create_collection (database, "collectionName", options, &error); if (!collection) { fprintf(stderr, "Got error: \"%s\" on line %d\n", error.message, __LINE__); return 1; } fam_flags (collection); fam_bypass (collection); fam_update (collection); fam_fields (collection); fam_sort (collection); mongoc_collection_drop (collection, NULL); bson_destroy (options); mongoc_database_destroy (database); mongoc_collection_destroy (collection); mongoc_client_destroy (client); return 0; }
static void test1 (void) { mongoc_collection_t *collection; mongoc_client_t *client; bson_error_t error = { 0 }; bool r; bson_t q = BSON_INITIALIZER; int i; BSON_ASSERT (cluster); bson_append_utf8 (&q, "hello", -1, "world", -1); client = ha_sharded_cluster_get_client (cluster); collection = mongoc_client_get_collection (client, "test", "test"); for (i = 0; i < 100; i++) { r = mongoc_collection_insert (collection, MONGOC_INSERT_NONE, &q, NULL, &error); BSON_ASSERT (r); BSON_ASSERT (!error.domain); BSON_ASSERT (!error.code); } mongoc_collection_destroy (collection); mongoc_client_destroy (client); bson_destroy (&q); }
int mainnn(int argc, char** argv) { mongoc_init(); mongoc_client_t *client; mongoc_database_t *database; mongoc_collection_t *collection; client = mongoc_client_new("mongodb://localhost/?appname=insert-example"); database = mongoc_client_get_database(client, "test"); collection = mongoc_client_get_collection(client, "test", "devices"); iot::messaging::Message m(m1); std::cerr << m.toString() << std::endl; m.fromString(m2); std::cerr << m.toString() << std::endl; iot::messaging::Message mm; const std::string s = mm.toString(); std::cerr << mm.toString() << std::endl; mongoc_collection_destroy(collection); mongoc_database_destroy(database); mongoc_client_destroy(client); mongoc_cleanup(); return EXIT_SUCCESS; }
int main (int argc, char *argv[]) { bson_t *options; bson_error_t error; mongoc_client_t *client; mongoc_collection_t *collection; mongoc_database_t *database; mongoc_init (); client = mongoc_client_new ("mongodb://localhost/"); database = mongoc_client_get_database (client, "testasdf"); /* Create schema validator */ options = BCON_NEW ("validator", "{", "number", "{", "$gte", BCON_INT32 (5), "}", "}"); collection = mongoc_database_create_collection (database, "collname", options, &error); if (collection) { bulk5_fail (collection); bulk5_success (collection); mongoc_collection_destroy (collection); } else { fprintf(stderr, "Couldn't create collection: '%s'\n", error.message); } bson_free (options); mongoc_database_destroy (database); mongoc_client_destroy (client); mongoc_cleanup (); return 0; }
static void test_drop (void) { mongoc_collection_t *collection; mongoc_database_t *database; mongoc_client_t *client; bson_error_t error; bson_t *doc; bool r; client = mongoc_client_new(gTestUri); ASSERT (client); database = get_test_database (client); ASSERT (database); collection = get_test_collection (client, "test_drop"); ASSERT (collection); doc = BCON_NEW("hello", "world"); r = mongoc_collection_insert(collection, MONGOC_INSERT_NONE, doc, NULL, &error); bson_destroy (doc); ASSERT (r); r = mongoc_collection_drop(collection, &error); ASSERT (r == true); r = mongoc_collection_drop(collection, &error); ASSERT (r == false); mongoc_collection_destroy(collection); mongoc_database_destroy(database); mongoc_client_destroy(client); }
static int mongo_del_origin(u08bits *origin) { mongoc_collection_t * collection = mongo_get_collection("realm"); if(!collection) return -1; int ret = -1; bson_t query, doc, child; bson_init(&query); bson_init(&doc); bson_append_document_begin(&doc, "$pull", -1, &child); BSON_APPEND_UTF8(&child, "origin", (const char *)origin); bson_append_document_end(&doc, &child); if (!mongoc_collection_update(collection, MONGOC_UPDATE_MULTI_UPDATE, &query, &doc, NULL, NULL)) { TURN_LOG_FUNC(TURN_LOG_LEVEL_ERROR, "Error deleting origin information\n"); } else { ret = 0; } mongoc_collection_destroy(collection); bson_destroy(&query); bson_destroy(&doc); return ret; }
/** * Destroys the given collection, allowing you to connect to another one. * * @param collection The collection to destroy. */ void monary_destroy_collection(mongoc_collection_t* collection) { if (collection) { DEBUG("%s", "Closing mongoc_collection"); mongoc_collection_destroy(collection); } }
static int mongo_add_origin(u08bits *origin, u08bits *realm) { mongoc_collection_t * collection = mongo_get_collection("realm"); if(!collection) return -1; int ret = -1; u08bits realm0[STUN_MAX_REALM_SIZE+1] = "\0"; if(!realm) realm=realm0; bson_t query, doc, child; bson_init(&query); BSON_APPEND_UTF8(&query, "realm", (const char *)realm); bson_init(&doc); bson_append_document_begin(&doc, "$addToSet", -1, &child); BSON_APPEND_UTF8(&child, "origin", (const char *)origin); bson_append_document_end(&doc, &child); if (!mongoc_collection_update(collection, MONGOC_UPDATE_UPSERT, &query, &doc, NULL, NULL)) { TURN_LOG_FUNC(TURN_LOG_LEVEL_ERROR, "Error inserting/updating realm origin information\n"); } else { ret = 0; } mongoc_collection_destroy(collection); bson_destroy(&query); bson_destroy(&doc); return ret; }
static int mongo_set_oauth_key(oauth_key_data_raw *key) { mongoc_collection_t * collection = mongo_get_collection("oauth_key"); if(!collection) return -1; bson_t query; bson_init(&query); BSON_APPEND_UTF8(&query, "kid", (const char *)key->kid); bson_t doc; bson_init(&doc); BSON_APPEND_UTF8(&doc, "kid", (const char *)key->kid); BSON_APPEND_UTF8(&doc, "as_rs_alg", (const char *)key->as_rs_alg); BSON_APPEND_UTF8(&doc, "ikm_key", (const char *)key->ikm_key); BSON_APPEND_INT64(&doc, "timestamp", (int64_t)key->timestamp); BSON_APPEND_INT32(&doc, "lifetime", (int32_t)key->lifetime); int ret = -1; if (!mongoc_collection_update(collection, MONGOC_UPDATE_UPSERT, &query, &doc, NULL, NULL)) { TURN_LOG_FUNC(TURN_LOG_LEVEL_ERROR, "Error inserting/updating oauth key information\n"); } else { ret = 0; } mongoc_collection_destroy(collection); bson_destroy(&doc); bson_destroy(&query); return ret; }
static int mongo_set_user_key(u08bits *usname, u08bits *realm, const char *key) { mongoc_collection_t * collection = mongo_get_collection("turnusers_lt"); if(!collection) return -1; bson_t query; bson_init(&query); BSON_APPEND_UTF8(&query, "name", (const char *)usname); BSON_APPEND_UTF8(&query, "realm", (const char *)realm); bson_t doc; bson_init(&doc); BSON_APPEND_UTF8(&doc, "name", (const char *)usname); BSON_APPEND_UTF8(&doc, "realm", (const char *)realm); BSON_APPEND_UTF8(&doc, "hmackey", (const char *)key); int ret = -1; if (!mongoc_collection_update(collection, MONGOC_UPDATE_UPSERT, &query, &doc, NULL, NULL)) { TURN_LOG_FUNC(TURN_LOG_LEVEL_ERROR, "Error inserting/updating user key information\n"); } else { ret = 0; } mongoc_collection_destroy(collection); bson_destroy(&doc); bson_destroy(&query); return ret; }
int main (int argc, char *argv[]) { const char *default_uristr = "mongodb://localhost/test"; char *uristr; const char *database_name; mongoc_uri_t *uri; mongoc_client_t *client; mongoc_database_t *db; mongoc_collection_t *collection; mongoc_init (); uristr = getenv ("MONGODB_URI"); uristr = uristr ? uristr : (char*)default_uristr; uri = mongoc_uri_new (uristr); client = mongoc_client_new_from_uri (uri); database_name = mongoc_uri_get_database (uri); db = mongoc_client_get_database (client, database_name); collection = mongoc_database_get_collection (db, "test"); test_suite (db, collection); mongoc_collection_destroy (collection); mongoc_database_destroy (db); mongoc_client_destroy (client); mongoc_uri_destroy (uri); mongoc_cleanup (); return 0; }
static void test_rename (void) { mongoc_collection_t *collection; mongoc_client_t *client; bson_error_t error; bson_t doc = BSON_INITIALIZER; bool r; client = mongoc_client_new (gTestUri); ASSERT (client); collection = get_test_collection (client, "test_rename"); ASSERT (collection); r = mongoc_collection_insert (collection, MONGOC_INSERT_NONE, &doc, NULL, &error); assert (r); r = mongoc_collection_rename (collection, "test", "test_rename_2", false, &error); assert (r); r = mongoc_collection_drop (collection, &error); assert (r); mongoc_collection_destroy (collection); mongoc_client_destroy (client); bson_destroy (&doc); }
static void test_mongoc_client_authenticate (void) { mongoc_collection_t *collection; mongoc_database_t *database; mongoc_client_t *client; mongoc_cursor_t *cursor; const bson_t *doc; bson_error_t error; char *username; char *uri; bool r; bson_t q; username = gen_test_user (); uri = gen_good_uri (username); /* * Add a user to the test database. */ client = mongoc_client_new(gTestUri); database = mongoc_client_get_database(client, "test"); mongoc_database_remove_user (database, username, &error); r = mongoc_database_add_user(database, username, "testpass", NULL, NULL, &error); ASSERT_CMPINT(r, ==, 1); mongoc_database_destroy(database); mongoc_client_destroy(client); /* * Try authenticating with that user. */ bson_init(&q); client = mongoc_client_new(uri); collection = mongoc_client_get_collection(client, "test", "test"); cursor = mongoc_collection_find(collection, MONGOC_QUERY_NONE, 0, 1, 0, &q, NULL, NULL); r = mongoc_cursor_next(cursor, &doc); if (!r) { r = mongoc_cursor_error(cursor, &error); if (r) { MONGOC_ERROR("Authentication failure: \"%s\"", error.message); } assert(!r); } mongoc_cursor_destroy(cursor); /* * Remove all test users. */ database = mongoc_client_get_database (client, "test"); r = mongoc_database_remove_all_users (database, &error); assert (r); mongoc_database_destroy (database); mongoc_collection_destroy(collection); mongoc_client_destroy(client); bson_free (username); bson_free (uri); }
static void test_find_and_modify_opts (void) { mock_server_t *server; mongoc_client_t *client; mongoc_collection_t *collection; bson_error_t error; mongoc_find_and_modify_opts_t *opts; future_t *future; request_t *request; server = mock_server_with_autoismaster (0); mock_server_run (server); client = mongoc_client_new_from_uri (mock_server_get_uri (server)); collection = mongoc_client_get_collection (client, "db", "collection"); opts = mongoc_find_and_modify_opts_new (); assert (mongoc_find_and_modify_opts_set_max_time_ms (opts, 42)); assert (mongoc_find_and_modify_opts_append (opts, tmp_bson ("{'foo': 1}"))); future = future_collection_find_and_modify_with_opts ( collection, tmp_bson ("{}"), opts, NULL, &error); request = mock_server_receives_command ( server, "db", MONGOC_QUERY_NONE, "{'findAndModify': 'collection', 'maxTimeMS': 42, 'foo': 1}"); mock_server_replies_ok_and_destroys (request); ASSERT_OR_PRINT (future_get_bool (future), error); future_destroy (future); mongoc_find_and_modify_opts_destroy (opts); mongoc_collection_destroy (collection); mongoc_client_destroy (client); mock_server_destroy (server); }
static void run_command (void) { mongoc_client_t *client; mongoc_collection_t *collection; bson_error_t error; bson_t *command; bson_t reply; char *str; client = mongoc_client_new ("mongodb://*****:*****@192.168.0.112:27017/"); collection = mongoc_client_get_collection (client, "test", "test"); command = BCON_NEW ("collStats", BCON_UTF8 ("test")); if (mongoc_collection_command_simple (collection, command, NULL, &reply, &error)) { str = bson_as_json (&reply, NULL); printf ("%s\n", str); bson_free (str); } else { fprintf (stderr, "Failed to run command: %s\n", error.message); } bson_destroy (command); bson_destroy (&reply); mongoc_collection_destroy (collection); mongoc_client_destroy (client); }
static void test_regex (void) { mongoc_collection_t *collection; mongoc_client_t *client; bson_error_t error = { 0 }; int64_t count; bson_t q = BSON_INITIALIZER; client = mongoc_client_new (gTestUri); ASSERT (client); collection = mongoc_client_get_collection (client, "test", "test"); ASSERT (collection); bson_append_regex (&q, "hello", -1, "^/wo", NULL); count = mongoc_collection_count (collection, MONGOC_QUERY_NONE, &q, 0, 0, NULL, &error); ASSERT (count > 0); ASSERT (!error.domain); bson_destroy (&q); mongoc_collection_destroy (collection); mongoc_client_destroy (client); }
bool TMongoDriver::updateMulti(const QString &collection, const QVariantMap &criteria, const QVariantMap &object) { if (!isOpen()) { return false; } errorCode = 0; errorString.clear(); bson_error_t error; mongoc_collection_t *col = mongoc_client_get_collection(mongoClient, qPrintable(dbName), qPrintable(collection)); bool res = mongoc_collection_update(col, MONGOC_UPDATE_MULTI_UPDATE, (bson_t *)TBson::toBson(criteria).data(), (bson_t *)TBson::toBson(object).data(), nullptr, &error); setLastCommandStatus(mongoc_collection_get_last_error(col)); mongoc_collection_destroy(col); if (!res) { tSystemError("MongoDB UpdateMulti Error: %s", error.message); errorCode = error.code; errorString = QLatin1String(error.message); } return res; }
static void test_index (void) { mongoc_collection_t *collection; mongoc_client_t *client; mongoc_index_opt_t opt; bson_error_t error; bool r; bson_t keys; mongoc_index_opt_init(&opt); client = mongoc_client_new(gTestUri); ASSERT (client); collection = mongoc_client_get_collection(client, "test", "test"); ASSERT (collection); bson_init(&keys); bson_append_int32(&keys, "hello", -1, 1); r = mongoc_collection_ensure_index(collection, &keys, &opt, &error); ASSERT (r); r = mongoc_collection_ensure_index(collection, &keys, &opt, &error); ASSERT (r); r = mongoc_collection_drop_index(collection, "hello_1", &error); ASSERT (r); bson_destroy(&keys); mongoc_collection_destroy(collection); mongoc_client_destroy(client); }
int main (int argc, char *argv[]) { mongoc_client_t *client; mongoc_collection_t *collection; mongoc_cursor_t *cursor; const bson_t *doc; bson_t *query; char *str; mongoc_init (); client = mongoc_client_new ("mongodb://localhost:3001/"); collection = mongoc_client_get_collection (client, "meteor", "sensors"); query = bson_new (); cursor = mongoc_collection_find (collection, MONGOC_QUERY_NONE, 0, 0, 0, query, NULL, NULL); while (mongoc_cursor_next (cursor, &doc)) { str = bson_as_json (doc, NULL); printf ("%s\n", str); bson_free (str); } bson_destroy (query); mongoc_cursor_destroy (cursor); mongoc_collection_destroy (collection); mongoc_client_destroy (client); return 0; }
static void test_count (void) { mongoc_collection_t *collection; mongoc_client_t *client; bson_error_t error; int64_t count; bson_t b; client = mongoc_client_new(gTestUri); ASSERT (client); collection = mongoc_client_get_collection(client, "test", "test"); ASSERT (collection); bson_init(&b); count = mongoc_collection_count(collection, MONGOC_QUERY_NONE, &b, 0, 0, NULL, &error); bson_destroy(&b); if (count == -1) { MONGOC_WARNING("%s\n", error.message); } ASSERT (count != -1); mongoc_collection_destroy(collection); mongoc_client_destroy(client); }
bool mongoc_database_remove_all_users (mongoc_database_t *database, bson_error_t *error) { mongoc_collection_t *col; bson_error_t lerror; bson_t cmd; bool ret; ENTRY; bson_return_val_if_fail (database, false); bson_init (&cmd); BSON_APPEND_INT32 (&cmd, "dropAllUsersFromDatabase", 1); ret = mongoc_database_command_simple (database, &cmd, NULL, NULL, &lerror); bson_destroy (&cmd); if (!ret && (lerror.code == MONGOC_ERROR_QUERY_COMMAND_NOT_FOUND)) { bson_init (&cmd); col = mongoc_client_get_collection (database->client, database->name, "system.users"); BSON_ASSERT (col); ret = mongoc_collection_delete (col, MONGOC_DELETE_NONE, &cmd, NULL, error); bson_destroy (&cmd); mongoc_collection_destroy (col); } RETURN (ret); }
int main (int argc,char* argv[]) { mongoc_client_t *client; mongoc_collection_t *collection; mongoc_cursor_t *cursor; const bson_t *doc; bson_t *query; char *str; mongoc_init (); client = mongoc_client_new ("mongodb://*****:*****@192.168.0.112:27017/"); collection = mongoc_client_get_collection (client, "clown", "testCollection"); query = bson_new (); cursor = mongoc_collection_find (collection, MONGOC_QUERY_NONE, 0, 0, 0, query, NULL, NULL); while (mongoc_cursor_next (cursor, &doc)) { str = bson_as_json (doc, NULL); printf ("%s\n", str); bson_free (str); } bson_destroy (query); mongoc_cursor_destroy (cursor); mongoc_collection_destroy (collection); mongoc_client_destroy (client); return 0; }
/* * Release a result set from memory */ int db_mongodb_free_result(db1_con_t* _h, db1_res_t* _r) { if(!_r) return -1; if(RES_PTR(_r)) { if(((db_mongodb_result_t*)RES_PTR(_r))->rdoc) { bson_destroy(((db_mongodb_result_t*)RES_PTR(_r))->rdoc); ((db_mongodb_result_t*)RES_PTR(_r))->rdoc = NULL; } if(((db_mongodb_result_t*)RES_PTR(_r))->colsdoc) { bson_destroy (((db_mongodb_result_t*)RES_PTR(_r))->colsdoc); ((db_mongodb_result_t*)RES_PTR(_r))->colsdoc = NULL; } ((db_mongodb_result_t*)RES_PTR(_r))->nrcols = 0; if(((db_mongodb_result_t*)RES_PTR(_r))->cursor) { mongoc_cursor_destroy (((db_mongodb_result_t*)RES_PTR(_r))->cursor); ((db_mongodb_result_t*)RES_PTR(_r))->cursor = NULL; } if(((db_mongodb_result_t*)RES_PTR(_r))->collection) { mongoc_collection_destroy (((db_mongodb_result_t*)RES_PTR(_r))->collection); ((db_mongodb_result_t*)RES_PTR(_r))->collection = NULL; } pkg_free(RES_PTR(_r)); } db_free_result(_r); return 0; }
int main (int argc, char *argv[]) { mongoc_collection_t *collection; mongoc_client_t *client; if (argc != 2) { fprintf (stderr, "usage: %s MONGO_URI\n", argv[0]); return EXIT_FAILURE; } mongoc_init (); client = mongoc_client_new (argv[1]); if (!client) { fprintf (stderr, "Invalid URI: \"%s\"\n", argv[1]); return EXIT_FAILURE; } mongoc_client_set_error_api (client, 2); collection = mongoc_client_get_collection (client, "local", "oplog.rs"); tail_collection (collection); mongoc_collection_destroy (collection); mongoc_client_destroy (client); return 0; }
int mongo_get_documents(mongoc_client_t *client, char *database, char *collection_name, bson_t *query, query_result **result) { mongoc_collection_t *collection; mongoc_cursor_t *cursor; const bson_t *doc; char *str; int index = 0; collection = mongoc_client_get_collection(client, database, collection_name); cursor = mongoc_collection_find(collection, MONGOC_QUERY_NONE, 0, 0, 0, query, NULL, NULL); query_result *current = *result; while (mongoc_cursor_next(cursor, &doc)) { str = bson_as_json(doc, NULL); if (index == 0) { (*result)->document = malloc(strlen(str) + 1); strcpy((*result)->document, str); (*result)->next = NULL; } else { current->next = malloc(sizeof(query_result)); current->next->document = malloc(strlen(str) + 1); strcpy(current->next->document, str); current->next->next = NULL; current = current->next; } index++; bson_free(str); } mongoc_cursor_destroy(cursor); mongoc_collection_destroy(collection); return 0; }
static void test_mongoc_client_authenticate_failure (void) { mongoc_collection_t *collection; mongoc_cursor_t *cursor; mongoc_client_t *client; const bson_t *doc; bson_error_t error; bool r; bson_t q; /* * Try authenticating with that user. */ bson_init(&q); client = mongoc_client_new(gTestUriWithBadPassword); collection = mongoc_client_get_collection(client, "test", "test"); cursor = mongoc_collection_find(collection, MONGOC_QUERY_NONE, 0, 1, 0, &q, NULL, NULL); r = mongoc_cursor_next(cursor, &doc); assert(!r); r = mongoc_cursor_error(cursor, &error); assert(r); assert(error.domain == MONGOC_ERROR_CLIENT); assert(error.code == MONGOC_ERROR_CLIENT_AUTHENTICATE); mongoc_cursor_destroy(cursor); mongoc_collection_destroy(collection); mongoc_client_destroy(client); }