Mongo connect db

#include <stdio.h>
#include <mongoc/mongoc.h>

int main() {
    mongoc_client_t *client;
    mongoc_database_t *database;
    mongoc_collection_t *collection;
    bson_t *query;
    mongoc_cursor_t *cursor;
    const bson_t *doc;
    bson_error_t error;

    mongoc_init();

    client = mongoc_client_new("mongodb://localhost:27017");

    if (!client) {
        fprintf(stderr, "Failed to parse MongoDB connection string\n");
        return EXIT_FAILURE;
    }

    database = mongoc_client_get_database(client, "your_database_name");
    collection = mongoc_client_get_collection(client, "your_database_name", "your_collection_name");

    query = bson_new(); // Add your query conditions here

    cursor = mongoc_collection_find_with_opts(collection, query, NULL, NULL);

    while (mongoc_cursor_next(cursor, &doc)) {
        char *str = bson_as_json(doc, NULL);
        printf("%s\n", str);
        bson_free(str);
    }

    if (mongoc_cursor_error(cursor, &error)) {
        fprintf(stderr, "Cursor Error: %s\n", error.message);
    }

    bson_destroy(query);
    mongoc_cursor_destroy(cursor);
    mongoc_collection_destroy(collection);
    mongoc_database_destroy(database);
    mongoc_client_destroy(client);

    mongoc_cleanup();

    return EXIT_SUCCESS;
}