From 47255e9a248d501b508f8ecb38411ef881475fcf Mon Sep 17 00:00:00 2001 From: Kevin Albertson Date: Tue, 25 Mar 2025 08:47:14 -0400 Subject: [PATCH 1/4] CDRIVER-5942 remove deprecated count helpers --- NEWS | 1 + build/generate-future-functions.py | 21 - src/libmongoc/doc/errors.rst | 3 +- src/libmongoc/doc/mongoc_collection_count.rst | 85 ---- .../doc/mongoc_collection_count_documents.rst | 23 -- .../doc/mongoc_collection_count_with_opts.rst | 139 ------- src/libmongoc/doc/mongoc_collection_t.rst | 2 - src/libmongoc/src/mongoc/mongoc-collection.c | 111 ----- src/libmongoc/src/mongoc/mongoc-collection.h | 19 - src/libmongoc/tests/json-test-operations.c | 19 +- .../tests/mock_server/future-functions.c | 131 ------ .../tests/mock_server/future-functions.h | 27 -- .../tests/test-mongoc-client-session.c | 28 -- src/libmongoc/tests/test-mongoc-collection.c | 387 ------------------ .../tests/test-mongoc-hedged-reads.c | 4 +- .../tests/test-mongoc-max-staleness.c | 8 +- src/libmongoc/tests/test-mongoc-opts.c | 11 - .../tests/test-mongoc-read-concern.c | 12 - 18 files changed, 23 insertions(+), 1008 deletions(-) delete mode 100644 src/libmongoc/doc/mongoc_collection_count.rst delete mode 100644 src/libmongoc/doc/mongoc_collection_count_with_opts.rst diff --git a/NEWS b/NEWS index bf1e93bd96c..af94be89492 100644 --- a/NEWS +++ b/NEWS @@ -48,6 +48,7 @@ Unreleased (2.0.0) * Support for LibreSSL (the CMake option `ENABLE_SSL=LIBRESSL`) is removed. Associated API is removed (`MONGOC_ENABLE_SSL_LIBRESSL` and `mongoc_stream_tls_libressl_new`). * `MONGOC_WRITE_CONCERN_W_ERRORS_IGNORED` (value -1) is removed. Use `MONGOC_WRITE_CONCERN_W_UNACKNOWLEDGED` (value 0) which is handled equivalently. If specified in a URI, replace: `mongodb://host/?w=-1` with `mongodb://host/?w=0`. * The deprecated CMake option `ENABLE_AUTOMATIC_INIT_AND_CLEANUP` is removed. See [Initialization and cleanup](https://mongoc.org/libmongoc/1.30.2/init-cleanup.html) for expected use of `mongoc_init()` and `mongoc_cleanup()`. +* `mongoc_collection_count` and `mongoc_collection_count_with_opts` are removed. Use `mongoc_collection_count_documents` or `mongoc_collection_estimated_document_count` instead. ### Forwarding headers (`#include ` and `#include `) diff --git a/build/generate-future-functions.py b/build/generate-future-functions.py index a02d0579771..9f5bf4be6d0 100644 --- a/build/generate-future-functions.py +++ b/build/generate-future-functions.py @@ -215,27 +215,6 @@ param("const_bson_ptr", "options"), param("const_mongoc_read_prefs_ptr", "read_prefs")]), - future_function("int64_t", - "mongoc_collection_count", - [param("mongoc_collection_ptr", "collection"), - param("mongoc_query_flags_t", "flags"), - param("const_bson_ptr", "query"), - param("int64_t", "skip"), - param("int64_t", "limit"), - param("const_mongoc_read_prefs_ptr", "read_prefs"), - param("bson_error_ptr", "error")]), - - future_function("int64_t", - "mongoc_collection_count_with_opts", - [param("mongoc_collection_ptr", "collection"), - param("mongoc_query_flags_t", "flags"), - param("const_bson_ptr", "query"), - param("int64_t", "skip"), - param("int64_t", "limit"), - param("const_bson_ptr", "opts"), - param("const_mongoc_read_prefs_ptr", "read_prefs"), - param("bson_error_ptr", "error")]), - future_function("bool", "mongoc_collection_create_index_with_opts", [param("mongoc_collection_ptr", "collection"), diff --git a/src/libmongoc/doc/errors.rst b/src/libmongoc/doc/errors.rst index 37458ffee2d..176875fdb4f 100644 --- a/src/libmongoc/doc/errors.rst +++ b/src/libmongoc/doc/errors.rst @@ -160,8 +160,7 @@ To fix this flaw while preserving backward compatibility, the C Driver 1.4 intro | :symbol:`mongoc_database_command_with_opts`, and | | | | other command functions | | | +------------------------------------------------------+----------------------------------------+----------------------------------------+ -| :symbol:`mongoc_collection_count_with_opts` | ``MONGOC_ERROR_QUERY`` | ``MONGOC_ERROR_SERVER`` | -| :symbol:`mongoc_client_get_database_names_with_opts`,| | | +| :symbol:`mongoc_client_get_database_names_with_opts` | ``MONGOC_ERROR_QUERY`` | ``MONGOC_ERROR_SERVER`` | | and other command helper functions | | | +------------------------------------------------------+----------------------------------------+----------------------------------------+ | :symbol:`mongoc_collection_insert_one` | ``MONGOC_ERROR_COMMAND`` | ``MONGOC_ERROR_SERVER`` | diff --git a/src/libmongoc/doc/mongoc_collection_count.rst b/src/libmongoc/doc/mongoc_collection_count.rst deleted file mode 100644 index 83a7f7d1083..00000000000 --- a/src/libmongoc/doc/mongoc_collection_count.rst +++ /dev/null @@ -1,85 +0,0 @@ -:man_page: mongoc_collection_count - -mongoc_collection_count() -========================= - -.. warning:: - .. deprecated:: 1.11.0 - - Use :symbol:`mongoc_collection_count_documents` or :symbol:`mongoc_collection_estimated_document_count` instead. - - :symbol:`mongoc_collection_count_documents` has similar performance to calling :symbol:`mongoc_collection_count` with a non-NULL ``query``, and is guaranteed to retrieve an accurate collection count. See :ref:`migrating from deprecated count functions ` for details. - - :symbol:`mongoc_collection_estimated_document_count` has the same performance as calling :symbol:`mongoc_collection_count` with a NULL ``query``, but is not guaranteed to retrieve an accurate collection count. - -.. include:: includes/retryable-read.txt - -Synopsis --------- - -.. code-block:: c - - int64_t - mongoc_collection_count (mongoc_collection_t *collection, - mongoc_query_flags_t flags, - const bson_t *query, - int64_t skip, - int64_t limit, - const mongoc_read_prefs_t *read_prefs, - bson_error_t *error); - -Parameters ----------- - -* ``collection``: A :symbol:`mongoc_collection_t`. -* ``flags``: A :symbol:`mongoc_query_flags_t`. -* ``query``: A :symbol:`bson:bson_t` containing the query. -* ``skip``: A int64_t, zero to ignore. -* ``limit``: A int64_t, zero to ignore. -* ``read_prefs``: A :symbol:`mongoc_read_prefs_t` or ``NULL``. -* ``error``: An optional location for a :symbol:`bson_error_t ` or ``NULL``. - -Description ------------ - -This function shall execute a count query on the underlying 'collection'. The bson 'query' is not validated, simply passed along as appropriate to the server. As such, compatibility and errors should be validated in the appropriate server documentation. - -For more information, see the `query reference `_ at the MongoDB website. - -The :symbol:`mongoc_read_concern_t` specified on the :symbol:`mongoc_collection_t` will be used, if any. If ``read_prefs`` is NULL, the collection's read preferences are used. - -Errors ------- - -Errors are propagated via the ``error`` parameter. - -Returns -------- - --1 on failure, otherwise the number of documents counted. - -Example -------- - -.. code-block:: c - - #include - #include - #include - - static void - print_query_count (mongoc_collection_t *collection, bson_t *query) - { - bson_error_t error; - int64_t count; - - count = mongoc_collection_count ( - collection, MONGOC_QUERY_NONE, query, 0, 0, NULL, &error); - - if (count < 0) { - fprintf (stderr, "Count failed: %s\n", error.message); - } else { - printf ("%" PRId64 " documents counted.\n", count); - } - } - diff --git a/src/libmongoc/doc/mongoc_collection_count_documents.rst b/src/libmongoc/doc/mongoc_collection_count_documents.rst index 980161e923f..f9724212358 100644 --- a/src/libmongoc/doc/mongoc_collection_count_documents.rst +++ b/src/libmongoc/doc/mongoc_collection_count_documents.rst @@ -76,29 +76,6 @@ Example } } -.. _migrating-from-deprecated-count: - -Migrating from deprecated count functions ------------------------------------------ - -When migrating to :symbol:`mongoc_collection_count_documents` from the deprecated :symbol:`mongoc_collection_count` or :symbol:`mongoc_collection_count_with_opts`, the following query operators in the filter must be replaced: - -+-------------+-------------------------------------+ -| Operator | Replacement | -+=============+=====================================+ -| $where | `$expr`_ | -+-------------+-------------------------------------+ -| $near | `$geoWithin`_ with `$center`_ | -+-------------+-------------------------------------+ -| $nearSphere | `$geoWithin`_ with `$centerSphere`_ | -+-------------+-------------------------------------+ - -$expr requires MongoDB 3.6+ - -.. _$expr: https://www.mongodb.com/docs/manual/reference/operator/query/expr/ -.. _$geoWithin: https://www.mongodb.com/docs/manual/reference/operator/query/geoWithin/ -.. _$center: https://www.mongodb.com/docs/manual/reference/operator/query/center/#op._S_center -.. _$centerSphere: https://www.mongodb.com/docs/manual/reference/operator/query/centerSphere/#op._S_centerSphere .. seealso:: diff --git a/src/libmongoc/doc/mongoc_collection_count_with_opts.rst b/src/libmongoc/doc/mongoc_collection_count_with_opts.rst deleted file mode 100644 index 17312e832c8..00000000000 --- a/src/libmongoc/doc/mongoc_collection_count_with_opts.rst +++ /dev/null @@ -1,139 +0,0 @@ -:man_page: mongoc_collection_count_with_opts - -mongoc_collection_count_with_opts() -=================================== - -.. warning:: - .. deprecated:: 1.11.0 - - Use :symbol:`mongoc_collection_count_documents` or :symbol:`mongoc_collection_estimated_document_count` instead. - - :symbol:`mongoc_collection_count_documents` has similar performance to calling :symbol:`mongoc_collection_count` with a non-NULL ``query``, and is guaranteed to retrieve an accurate collection count. See :ref:`migrating from deprecated count functions ` for details. - - :symbol:`mongoc_collection_estimated_document_count` has the same performance as calling :symbol:`mongoc_collection_count` with a NULL ``query``, but is not guaranteed to retrieve an accurate collection count. - -Synopsis --------- - -.. code-block:: c - - int64_t - mongoc_collection_count_with_opts (mongoc_collection_t *collection, - mongoc_query_flags_t flags, - const bson_t *query, - int64_t skip, - int64_t limit, - const bson_t *opts, - const mongoc_read_prefs_t *read_prefs, - bson_error_t *error); - -Parameters ----------- - -* ``collection``: A :symbol:`mongoc_collection_t`. -* ``flags``: A :symbol:`mongoc_query_flags_t`. -* ``query``: A :symbol:`bson:bson_t` containing the query. -* ``skip``: A int64_t, zero to ignore. -* ``limit``: A int64_t, zero to ignore. -* ``opts``: A :symbol:`bson:bson_t`, ``NULL`` to ignore. -* ``read_prefs``: An optional :symbol:`mongoc_read_prefs_t`, otherwise uses the collection's read preference. -* ``error``: An optional location for a :symbol:`bson_error_t ` or ``NULL``. - -.. |opts-source| replace:: ``collection`` - -.. include:: includes/read-opts.txt - -Description ------------ - -This function shall execute a count query on the underlying 'collection'. The bson 'query' is not validated, simply passed along as appropriate to the server. As such, compatibility and errors should be validated in the appropriate server documentation. - -The :symbol:`mongoc_read_concern_t` specified on the :symbol:`mongoc_collection_t` will be used, if any. If ``read_prefs`` is NULL, the collection's read preferences are used. - -In addition to the standard functionality available from mongoc_collection_count, this function allows the user to add arbitrary extra keys to the count. This pass through enables features such as hinting for counts. - -For more information, see the `query reference `_ at the MongoDB website. - -.. include:: includes/retryable-read.txt - -Errors ------- - -Errors are propagated via the ``error`` parameter. - -Returns -------- - --1 on failure, otherwise the number of documents counted. - -Examples --------- - -.. code-block:: c - :caption: Basic Counting - - #include - #include - #include - - static void - print_query_count (mongoc_collection_t *collection, bson_t *query) - { - bson_error_t error; - int64_t count; - bson_t opts; - - bson_init (&opts); - BSON_APPEND_UTF8 (&opts, "hint", "_id_"); - - count = mongoc_collection_count_with_opts ( - collection, MONGOC_QUERY_NONE, query, 0, 0, &opts, NULL, &error); - - bson_destroy (&opts); - - if (count < 0) { - fprintf (stderr, "Count failed: %s\n", error.message); - } else { - printf ("%" PRId64 " documents counted.\n", count); - } - } - -.. code-block:: c - :caption: Counting with Collation - - #include - #include - #include - - static void - print_query_count (mongoc_collection_t *collection, bson_t *query) - { - bson_t *selector; - bson_t *opts; - bson_error_t error; - int64_t count; - - selector = BCON_NEW ("_id", "{", "$gt", BCON_UTF8 ("one"), "}"); - - /* "One" normally sorts before "one"; make "one" come first */ - opts = BCON_NEW ("collation", - "{", - "locale", - BCON_UTF8 ("en_US"), - "caseFirst", - BCON_UTF8 ("lower"), - "}"); - - count = mongoc_collection_count_with_opts ( - collection, MONGOC_QUERY_NONE, query, 0, 0, opts, NULL, &error); - - bson_destroy (selector); - bson_destroy (opts); - - if (count < 0) { - fprintf (stderr, "Count failed: %s\n", error.message); - } else { - printf ("%" PRId64 " documents counted.\n", count); - } - } - diff --git a/src/libmongoc/doc/mongoc_collection_t.rst b/src/libmongoc/doc/mongoc_collection_t.rst index b1ee767f257..9247724bb88 100644 --- a/src/libmongoc/doc/mongoc_collection_t.rst +++ b/src/libmongoc/doc/mongoc_collection_t.rst @@ -32,8 +32,6 @@ Read preferences and write concerns are inherited from the parent client. They c mongoc_collection_copy mongoc_collection_count_documents mongoc_collection_estimated_document_count - mongoc_collection_count - mongoc_collection_count_with_opts mongoc_collection_create_bulk_operation mongoc_collection_create_bulk_operation_with_opts mongoc_collection_create_index diff --git a/src/libmongoc/src/mongoc/mongoc-collection.c b/src/libmongoc/src/mongoc/mongoc-collection.c index e896b95aad3..e9cfe68c883 100644 --- a/src/libmongoc/src/mongoc/mongoc-collection.c +++ b/src/libmongoc/src/mongoc/mongoc-collection.c @@ -579,117 +579,6 @@ mongoc_collection_command_simple (mongoc_collection_t *collection, error); } -/* - *-------------------------------------------------------------------------- - * - * mongoc_collection_count -- - * - * Count the number of documents matching @query. - * - * Parameters: - * @flags: A mongoc_query_flags_t describing the query flags or 0. - * @query: The query to perform or NULL for {}. - * @skip: The $skip to perform within the query or 0. - * @limit: The $limit to perform within the query or 0. - * @read_prefs: desired read preferences or NULL. - * @error: A location for an error or NULL. - * - * Returns: - * -1 on failure; otherwise the number of matching documents. - * - * Side effects: - * @error is set upon failure if non-NULL. - * - *-------------------------------------------------------------------------- - */ - -int64_t -mongoc_collection_count (mongoc_collection_t *collection, /* IN */ - mongoc_query_flags_t flags, /* IN */ - const bson_t *query, /* IN */ - int64_t skip, /* IN */ - int64_t limit, /* IN */ - const mongoc_read_prefs_t *read_prefs, /* IN */ - bson_error_t *error) /* OUT */ -{ - int64_t ret; - bson_t opts = BSON_INITIALIZER; - - /* Complex types must be parts of `opts`, otherwise we can't - * follow various specs that require validation etc */ - if (collection->read_concern->level != NULL) { - const bson_t *read_concern_bson; - - read_concern_bson = _mongoc_read_concern_get_bson (collection->read_concern); - BSON_APPEND_DOCUMENT (&opts, "readConcern", read_concern_bson); - } - - /* Server Selection Spec: "may-use-secondary" commands SHOULD take a read - * preference argument and otherwise MUST use the default read preference - * from client, database or collection configuration. */ - BEGIN_IGNORE_DEPRECATIONS - ret = mongoc_collection_count_with_opts (collection, flags, query, skip, limit, &opts, read_prefs, error); - END_IGNORE_DEPRECATIONS - - bson_destroy (&opts); - return ret; -} - - -int64_t -mongoc_collection_count_with_opts (mongoc_collection_t *collection, /* IN */ - mongoc_query_flags_t flags, /* IN */ - const bson_t *query, /* IN */ - int64_t skip, /* IN */ - int64_t limit, /* IN */ - const bson_t *opts, /* IN */ - const mongoc_read_prefs_t *read_prefs, /* IN */ - bson_error_t *error) /* OUT */ -{ - bson_iter_t iter; - int64_t ret = -1; - bool success; - bson_t reply; - bson_t cmd = BSON_INITIALIZER; - - ENTRY; - - BSON_ASSERT_PARAM (collection); - - bsonBuildAppend (cmd, - kv ("count", utf8_w_len (collection->collection, collection->collectionlen)), - kv ("query", - if (query, // If we have a query, - then (bson (*query)), // Copy it - else (doc ()))), // Otherwise, add an empty doc - if (limit, then (kv ("limit", int64 (limit)))), - if (skip, then (kv ("skip", int64 (skip))))); - - - success = _mongoc_client_command_with_opts (collection->client, - collection->db, - &cmd, - MONGOC_CMD_READ, - opts, - flags, - read_prefs, - collection->read_prefs, - collection->read_concern, - collection->write_concern, - &reply, - error); - - if (success) { - if (bson_iter_init_find (&iter, &reply, "n")) { - ret = bson_iter_as_int64 (&iter); - } - } - - bson_destroy (&reply); - bson_destroy (&cmd); - - RETURN (ret); -} int64_t mongoc_collection_estimated_document_count (mongoc_collection_t *coll, diff --git a/src/libmongoc/src/mongoc/mongoc-collection.h b/src/libmongoc/src/mongoc/mongoc-collection.h index df64562d755..ae213d9e98f 100644 --- a/src/libmongoc/src/mongoc/mongoc-collection.h +++ b/src/libmongoc/src/mongoc/mongoc-collection.h @@ -86,25 +86,6 @@ mongoc_collection_command_simple (mongoc_collection_t *collection, bson_t *reply, bson_error_t *error); -BSON_DEPRECATED_FOR (mongoc_collection_count_documents or mongoc_collection_estimated_document_count) -MONGOC_EXPORT (int64_t) mongoc_collection_count (mongoc_collection_t *collection, - mongoc_query_flags_t flags, - const bson_t *query, - int64_t skip, - int64_t limit, - const mongoc_read_prefs_t *read_prefs, - bson_error_t *error); - -BSON_DEPRECATED_FOR (mongoc_collection_count_documents or mongoc_collection_estimated_document_count) -MONGOC_EXPORT (int64_t) mongoc_collection_count_with_opts (mongoc_collection_t *collection, - mongoc_query_flags_t flags, - const bson_t *query, - int64_t skip, - int64_t limit, - const bson_t *opts, - const mongoc_read_prefs_t *read_prefs, - bson_error_t *error); - MONGOC_EXPORT (bool) mongoc_collection_drop (mongoc_collection_t *collection, bson_error_t *error); diff --git a/src/libmongoc/tests/json-test-operations.c b/src/libmongoc/tests/json-test-operations.c index 809ed932420..5af9c2469ba 100644 --- a/src/libmongoc/tests/json-test-operations.c +++ b/src/libmongoc/tests/json-test-operations.c @@ -1229,10 +1229,21 @@ count (mongoc_collection_t *collection, } else if (!strcmp (name, "estimatedDocumentCount")) { r = mongoc_collection_estimated_document_count (collection, &opts, read_prefs, reply, &error); } else if (!strcmp (name, "count")) { - /* deprecated old count function */ - r = mongoc_collection_count_with_opts (collection, MONGOC_QUERY_NONE, &filter, 0, 0, &opts, read_prefs, &error); - /* fake a reply for the test framework's sake */ - bson_init (reply); + // "count" previously referred to the deprecated helper: `mongoc_collection_count_with_opts`. + // Run the "count" command directly to support tests. See: CRUD spec "Count API Details". + bson_t *cmd = BCON_NEW ("count", mongoc_collection_get_name (collection)); + BSON_ASSERT (BSON_APPEND_DOCUMENT (cmd, "query", &filter)); + BSON_ASSERT (bson_concat (cmd, &opts)); + bool ok = mongoc_collection_command_simple (collection, cmd, read_prefs, reply, &error); + if (!ok) { + // Set resulting count to -1 to indicate failure. + r = -1; + } else { + bson_iter_t iter; + BSON_ASSERT (bson_iter_init_find (&iter, reply, "n")); + r = bson_iter_as_int64 (&iter); + } + bson_destroy (cmd); } else { test_error ("count() called with unrecognized operation name %s", name); return false; diff --git a/src/libmongoc/tests/mock_server/future-functions.c b/src/libmongoc/tests/mock_server/future-functions.c index bdc107aff83..4562f8a82f7 100644 --- a/src/libmongoc/tests/mock_server/future-functions.c +++ b/src/libmongoc/tests/mock_server/future-functions.c @@ -301,57 +301,6 @@ BSON_THREAD_FUN (background_mongoc_collection_aggregate, data) BSON_THREAD_RETURN; } -static -BSON_THREAD_FUN (background_mongoc_collection_count, data) -{ - future_t *future = (future_t *) data; - future_value_t return_value; - - return_value.type = future_value_int64_t_type; - - future_value_set_int64_t ( - &return_value, - mongoc_collection_count ( - future_value_get_mongoc_collection_ptr (future_get_param (future, 0)), - future_value_get_mongoc_query_flags_t (future_get_param (future, 1)), - future_value_get_const_bson_ptr (future_get_param (future, 2)), - future_value_get_int64_t (future_get_param (future, 3)), - future_value_get_int64_t (future_get_param (future, 4)), - future_value_get_const_mongoc_read_prefs_ptr (future_get_param (future, 5)), - future_value_get_bson_error_ptr (future_get_param (future, 6)) - )); - - future_resolve (future, return_value); - - BSON_THREAD_RETURN; -} - -static -BSON_THREAD_FUN (background_mongoc_collection_count_with_opts, data) -{ - future_t *future = (future_t *) data; - future_value_t return_value; - - return_value.type = future_value_int64_t_type; - - future_value_set_int64_t ( - &return_value, - mongoc_collection_count_with_opts ( - future_value_get_mongoc_collection_ptr (future_get_param (future, 0)), - future_value_get_mongoc_query_flags_t (future_get_param (future, 1)), - future_value_get_const_bson_ptr (future_get_param (future, 2)), - future_value_get_int64_t (future_get_param (future, 3)), - future_value_get_int64_t (future_get_param (future, 4)), - future_value_get_const_bson_ptr (future_get_param (future, 5)), - future_value_get_const_mongoc_read_prefs_ptr (future_get_param (future, 6)), - future_value_get_bson_error_ptr (future_get_param (future, 7)) - )); - - future_resolve (future, return_value); - - BSON_THREAD_RETURN; -} - static BSON_THREAD_FUN (background_mongoc_collection_create_index_with_opts, data) { @@ -1664,86 +1613,6 @@ future_collection_aggregate ( return future; } -future_t * -future_collection_count ( - mongoc_collection_ptr collection, - mongoc_query_flags_t flags, - const_bson_ptr query, - int64_t skip, - int64_t limit, - const_mongoc_read_prefs_ptr read_prefs, - bson_error_ptr error) -{ - future_t *future = future_new (future_value_int64_t_type, - 7); - - future_value_set_mongoc_collection_ptr ( - future_get_param (future, 0), collection); - - future_value_set_mongoc_query_flags_t ( - future_get_param (future, 1), flags); - - future_value_set_const_bson_ptr ( - future_get_param (future, 2), query); - - future_value_set_int64_t ( - future_get_param (future, 3), skip); - - future_value_set_int64_t ( - future_get_param (future, 4), limit); - - future_value_set_const_mongoc_read_prefs_ptr ( - future_get_param (future, 5), read_prefs); - - future_value_set_bson_error_ptr ( - future_get_param (future, 6), error); - - future_start (future, background_mongoc_collection_count); - return future; -} - -future_t * -future_collection_count_with_opts ( - mongoc_collection_ptr collection, - mongoc_query_flags_t flags, - const_bson_ptr query, - int64_t skip, - int64_t limit, - const_bson_ptr opts, - const_mongoc_read_prefs_ptr read_prefs, - bson_error_ptr error) -{ - future_t *future = future_new (future_value_int64_t_type, - 8); - - future_value_set_mongoc_collection_ptr ( - future_get_param (future, 0), collection); - - future_value_set_mongoc_query_flags_t ( - future_get_param (future, 1), flags); - - future_value_set_const_bson_ptr ( - future_get_param (future, 2), query); - - future_value_set_int64_t ( - future_get_param (future, 3), skip); - - future_value_set_int64_t ( - future_get_param (future, 4), limit); - - future_value_set_const_bson_ptr ( - future_get_param (future, 5), opts); - - future_value_set_const_mongoc_read_prefs_ptr ( - future_get_param (future, 6), read_prefs); - - future_value_set_bson_error_ptr ( - future_get_param (future, 7), error); - - future_start (future, background_mongoc_collection_count_with_opts); - return future; -} - future_t * future_collection_create_index_with_opts ( mongoc_collection_ptr collection, diff --git a/src/libmongoc/tests/mock_server/future-functions.h b/src/libmongoc/tests/mock_server/future-functions.h index bc03bcf5aaa..505e2e0b212 100644 --- a/src/libmongoc/tests/mock_server/future-functions.h +++ b/src/libmongoc/tests/mock_server/future-functions.h @@ -149,33 +149,6 @@ future_collection_aggregate ( ); -future_t * -future_collection_count ( - - mongoc_collection_ptr collection, - mongoc_query_flags_t flags, - const_bson_ptr query, - int64_t skip, - int64_t limit, - const_mongoc_read_prefs_ptr read_prefs, - bson_error_ptr error -); - - -future_t * -future_collection_count_with_opts ( - - mongoc_collection_ptr collection, - mongoc_query_flags_t flags, - const_bson_ptr query, - int64_t skip, - int64_t limit, - const_bson_ptr opts, - const_mongoc_read_prefs_ptr read_prefs, - bson_error_ptr error -); - - future_t * future_collection_create_index_with_opts ( diff --git a/src/libmongoc/tests/test-mongoc-client-session.c b/src/libmongoc/tests/test-mongoc-client-session.c index 4371c407454..c68c8d5c316 100644 --- a/src/libmongoc/tests/test-mongoc-client-session.c +++ b/src/libmongoc/tests/test-mongoc-client-session.c @@ -1600,15 +1600,6 @@ run_session_test_bulk_operation (void *ctx) } -static void -run_count_test (void *ctx) -{ - /* CDRIVER-3612: mongoc_collection_estimated_document_count does not support - * explicit sessions */ - _test_implicit_session_lsid (((session_test_helper_t *) ctx)->test_fn); -} - - static void insert_10_docs (session_test_t *test) { @@ -1681,14 +1672,6 @@ test_db_cmd (session_test_t *test) } -static void -test_count (session_test_t *test) -{ - test->succeeded = (-1 != mongoc_collection_count_with_opts ( - test->collection, MONGOC_QUERY_NONE, NULL, 0, 0, &test->opts, NULL, &test->error)); -} - - static void test_cursor (session_test_t *test) { @@ -2747,17 +2730,6 @@ test_session_install (TestSuite *suite) add_session_test (suite, "/Session/write_cmd", test_write_cmd, false); add_session_test (suite, "/Session/read_write_cmd", test_read_write_cmd, true); add_session_test (suite, "/Session/db_cmd", test_db_cmd, false); - { - session_test_helper_t *const helper = bson_malloc (sizeof (*helper)); - *helper = (session_test_helper_t){.test_fn = test_count}; - TestSuite_AddFull (suite, - "/Session/count", - run_count_test, - bson_free, - helper, - test_framework_skip_if_no_cluster_time, - test_framework_skip_if_no_crypto); - } add_session_test (suite, "/Session/cursor", test_cursor, true); add_session_test (suite, "/Session/drop", test_drop, false); add_session_test (suite, "/Session/drop_index", test_drop_index, false); diff --git a/src/libmongoc/tests/test-mongoc-collection.c b/src/libmongoc/tests/test-mongoc-collection.c index b177ebfea56..187e136a5c1 100644 --- a/src/libmongoc/tests/test-mongoc-collection.c +++ b/src/libmongoc/tests/test-mongoc-collection.c @@ -336,10 +336,6 @@ test_read_prefs_is_valid (void *ctx) ASSERT (!mongoc_collection_command_simple (collection, tmp_bson ("{'ping': 1}"), read_prefs, &reply, &error)); bson_destroy (&reply); - /* mongoc_collection_count_with_opts */ - ASSERT (mongoc_collection_count_with_opts ( - collection, MONGOC_QUERY_NONE, tmp_bson ("{}"), 0, 0, NULL, read_prefs, &error) == -1); - /* mongoc_collection_find */ cursor = mongoc_collection_find (collection, MONGOC_QUERY_NONE, 0, 0, 0, tmp_bson ("{}"), NULL, read_prefs); @@ -370,10 +366,6 @@ test_read_prefs_is_valid (void *ctx) ASSERT_OR_PRINT (mongoc_collection_command_simple (collection, tmp_bson ("{'ping': 1}"), read_prefs, &reply, &error), error); bson_destroy (&reply); - /* mongoc_collection_count_with_opts */ - ASSERT_OR_PRINT (mongoc_collection_count_with_opts ( - collection, MONGOC_QUERY_NONE, tmp_bson ("{}"), 0, 0, NULL, read_prefs, &error) != -1, - error); /* mongoc_collection_find */ cursor = mongoc_collection_find (collection, MONGOC_QUERY_NONE, 0, 0, 0, tmp_bson ("{}"), NULL, read_prefs); @@ -1717,304 +1709,6 @@ test_index_storage (void) mongoc_client_destroy (client); } -static void -test_count (void) -{ - mongoc_collection_t *collection; - mongoc_client_t *client; - bson_error_t error; - int64_t count; - bson_t b; - - client = test_framework_new_default_client (); - 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); -} - - -static void -test_count_read_pref (void) -{ - mock_server_t *server; - mongoc_collection_t *collection; - mongoc_client_t *client; - mongoc_read_prefs_t *prefs; - future_t *future; - request_t *request; - bson_error_t error; - - server = mock_mongos_new (WIRE_VERSION_MIN); - mock_server_run (server); - mock_server_auto_endsessions (server); - client = test_framework_client_new_from_uri (mock_server_get_uri (server), NULL); - collection = mongoc_client_get_collection (client, "db", "collection"); - prefs = mongoc_read_prefs_new (MONGOC_READ_SECONDARY); - - mongoc_collection_set_read_prefs (collection, prefs); - future = future_collection_count (collection, MONGOC_QUERY_NONE, NULL, 0, 0, NULL, &error); - request = mock_server_receives_msg (server, - MONGOC_MSG_NONE, - tmp_bson ("{'$db': 'db'," - " 'count': 'collection'," - " '$readPreference': {'mode': 'secondary'}}")); - - reply_to_request_simple (request, "{'ok': 1, 'n': 1}"); - ASSERT_OR_PRINT (1 == future_get_int64_t (future), error); - - request_destroy (request); - future_destroy (future); - mongoc_read_prefs_destroy (prefs); - mongoc_collection_destroy (collection); - mongoc_client_destroy (client); - mock_server_destroy (server); -} - - -static void -test_count_read_concern (void) -{ - mongoc_collection_t *collection; - mongoc_client_t *client; - mongoc_read_concern_t *rc; - mock_server_t *server; - request_t *request; - bson_error_t error; - future_t *future; - int64_t count; - bson_t b; - - server = mock_server_with_auto_hello (WIRE_VERSION_MIN); - mock_server_run (server); - client = test_framework_client_new_from_uri (mock_server_get_uri (server), NULL); - ASSERT (client); - - collection = mongoc_client_get_collection (client, "test", "test"); - ASSERT (collection); - - bson_init (&b); - future = future_collection_count (collection, MONGOC_QUERY_NONE, &b, 0, 0, NULL, &error); - bson_destroy (&b); - request = - mock_server_receives_msg (server, MONGOC_MSG_NONE, tmp_bson ("{'$db': 'test', 'count': 'test', 'query': {}}")); - - reply_to_request_simple (request, "{ 'n' : 42, 'ok' : 1 } "); - count = future_get_int64_t (future); - ASSERT_OR_PRINT (count == 42, error); - request_destroy (request); - future_destroy (future); - - /* readConcern: { level: majority } */ - rc = mongoc_read_concern_new (); - mongoc_read_concern_set_level (rc, MONGOC_READ_CONCERN_LEVEL_MAJORITY); - mongoc_collection_set_read_concern (collection, rc); - - bson_init (&b); - future = future_collection_count (collection, MONGOC_QUERY_NONE, &b, 0, 0, NULL, &error); - bson_destroy (&b); - request = mock_server_receives_msg (server, - MONGOC_MSG_NONE, - tmp_bson ("{'$db': 'test'," - " 'count': 'test'," - " 'query': {}," - " 'readConcern': {'level': 'majority'}}")); - - reply_to_request_simple (request, "{ 'n' : 43, 'ok' : 1 } "); - count = future_get_int64_t (future); - ASSERT_OR_PRINT (count == 43, error); - mongoc_read_concern_destroy (rc); - request_destroy (request); - future_destroy (future); - - /* readConcern: { level: local } */ - rc = mongoc_read_concern_new (); - mongoc_read_concern_set_level (rc, MONGOC_READ_CONCERN_LEVEL_LOCAL); - mongoc_collection_set_read_concern (collection, rc); - - bson_init (&b); - future = future_collection_count (collection, MONGOC_QUERY_NONE, &b, 0, 0, NULL, &error); - bson_destroy (&b); - request = mock_server_receives_msg (server, - MONGOC_MSG_NONE, - tmp_bson ("{'$db': 'test'," - " 'count': 'test'," - " 'query': {}," - " 'readConcern': {'level': 'local'}}")); - - reply_to_request_simple (request, "{ 'n' : 44, 'ok' : 1 } "); - count = future_get_int64_t (future); - ASSERT_OR_PRINT (count == 44, error); - mongoc_read_concern_destroy (rc); - request_destroy (request); - future_destroy (future); - - /* readConcern: { level: futureCompatible } */ - rc = mongoc_read_concern_new (); - mongoc_read_concern_set_level (rc, "futureCompatible"); - mongoc_collection_set_read_concern (collection, rc); - - bson_init (&b); - future = future_collection_count (collection, MONGOC_QUERY_NONE, &b, 0, 0, NULL, &error); - bson_destroy (&b); - request = mock_server_receives_msg (server, - MONGOC_MSG_NONE, - tmp_bson ("{'$db': 'test'," - " 'count': 'test'," - " 'query': {}," - " 'readConcern': {'level': 'futureCompatible'}}")); - - reply_to_request_simple (request, "{ 'n' : 45, 'ok' : 1 } "); - count = future_get_int64_t (future); - ASSERT_OR_PRINT (count == 45, error); - mongoc_read_concern_destroy (rc); - request_destroy (request); - future_destroy (future); - - /* Setting readConcern to NULL should not send readConcern */ - rc = mongoc_read_concern_new (); - mongoc_read_concern_set_level (rc, NULL); - mongoc_collection_set_read_concern (collection, rc); - - bson_init (&b); - future = future_collection_count (collection, MONGOC_QUERY_NONE, &b, 0, 0, NULL, &error); - bson_destroy (&b); - request = mock_server_receives_msg (server, - MONGOC_MSG_NONE, - tmp_bson ("{'$db': 'test'," - " 'count': 'test'," - " 'query': {}," - " 'readConcern': { '$exists': false }}")); - - reply_to_request_simple (request, "{ 'n' : 46, 'ok' : 1 } "); - count = future_get_int64_t (future); - ASSERT_OR_PRINT (count == 46, error); - mongoc_read_concern_destroy (rc); - request_destroy (request); - future_destroy (future); - - /* Fresh read_concern should not send readConcern */ - rc = mongoc_read_concern_new (); - mongoc_collection_set_read_concern (collection, rc); - - bson_init (&b); - future = future_collection_count (collection, MONGOC_QUERY_NONE, &b, 0, 0, NULL, &error); - bson_destroy (&b); - request = mock_server_receives_msg (server, - MONGOC_MSG_NONE, - tmp_bson ("{'$db': 'test'," - " 'count': 'test'," - " 'query': {}," - " 'readConcern': { '$exists': false }}")); - - reply_to_request_simple (request, "{ 'n' : 47, 'ok' : 1 } "); - count = future_get_int64_t (future); - ASSERT_OR_PRINT (count == 47, error); - - mongoc_read_concern_destroy (rc); - request_destroy (request); - future_destroy (future); - mongoc_collection_destroy (collection); - mongoc_client_destroy (client); - mock_server_destroy (server); -} - - -static void -test_count_read_concern_live (void *unused) -{ - mongoc_collection_t *collection; - mongoc_client_t *client; - mongoc_read_concern_t *rc; - bson_error_t error; - int64_t count; - bson_t b; - - BSON_UNUSED (unused); - - client = test_framework_new_default_client (); - ASSERT (client); - - collection = mongoc_client_get_collection (client, "test", "test"); - ASSERT (collection); - - // Drop collection. - // Use writeConcern=majority so later readConcern=majority observes dropped - // collection. - { - mongoc_write_concern_t *wc = mongoc_write_concern_new (); - mongoc_write_concern_set_w (wc, MONGOC_WRITE_CONCERN_W_MAJORITY); - bson_t drop_opts = BSON_INITIALIZER; - mongoc_write_concern_append (wc, &drop_opts); - if (!mongoc_collection_drop_with_opts (collection, &drop_opts, &error)) { - // Ignore an "ns not found" error. - if (NULL == strstr (error.message, "ns not found")) { - ASSERT_OR_PRINT (false, error); - } - } - - bson_destroy (&drop_opts); - mongoc_write_concern_destroy (wc); - } - - bson_init (&b); - count = mongoc_collection_count (collection, MONGOC_QUERY_NONE, &b, 0, 0, NULL, &error); - bson_destroy (&b); - ASSERT_OR_PRINT (count != -1, error); - ASSERT_CMPINT64 (count, ==, 0); - - /* Setting readConcern to NULL should not send readConcern */ - rc = mongoc_read_concern_new (); - mongoc_read_concern_set_level (rc, NULL); - mongoc_collection_set_read_concern (collection, rc); - - bson_init (&b); - count = mongoc_collection_count (collection, MONGOC_QUERY_NONE, &b, 0, 0, NULL, &error); - bson_destroy (&b); - ASSERT_OR_PRINT (count != -1, error); - ASSERT_CMPINT64 (count, ==, 0); - mongoc_read_concern_destroy (rc); - - /* readConcern: { level: local } should raise error pre 3.2 */ - rc = mongoc_read_concern_new (); - mongoc_read_concern_set_level (rc, MONGOC_READ_CONCERN_LEVEL_LOCAL); - mongoc_collection_set_read_concern (collection, rc); - - bson_init (&b); - count = mongoc_collection_count (collection, MONGOC_QUERY_NONE, &b, 0, 0, NULL, &error); - bson_destroy (&b); - ASSERT_OR_PRINT (count != -1, error); - ASSERT_CMPINT64 (count, ==, 0); - mongoc_read_concern_destroy (rc); - - /* readConcern: { level: majority } should raise error pre 3.2 */ - rc = mongoc_read_concern_new (); - mongoc_read_concern_set_level (rc, MONGOC_READ_CONCERN_LEVEL_MAJORITY); - mongoc_collection_set_read_concern (collection, rc); - - bson_init (&b); - count = mongoc_collection_count (collection, MONGOC_QUERY_NONE, &b, 0, 0, NULL, &error); - bson_destroy (&b); - ASSERT_OR_PRINT (count != -1, error); - ASSERT_CMPINT64 (count, ==, 0); - mongoc_read_concern_destroy (rc); - - mongoc_collection_destroy (collection); - mongoc_client_destroy (client); -} - int skip_unless_server_has_decimal128 (void) { @@ -2037,76 +1731,6 @@ mongod_supports_majority_read_concern (void) } -static void -test_count_with_opts (void) -{ - mock_server_t *server; - mongoc_collection_t *collection; - mongoc_client_t *client; - future_t *future; - request_t *request; - bson_error_t error; - - /* use a mongos since we don't send SECONDARY_OK to mongos by default */ - server = mock_mongos_new (WIRE_VERSION_MIN); - mock_server_run (server); - mock_server_auto_endsessions (server); - client = test_framework_client_new_from_uri (mock_server_get_uri (server), NULL); - collection = mongoc_client_get_collection (client, "db", "collection"); - - future = future_collection_count_with_opts ( - collection, MONGOC_QUERY_SECONDARY_OK, NULL, 0, 0, tmp_bson ("{'opt': 1}"), NULL, &error); - - request = - mock_server_receives_msg (server, MONGOC_MSG_NONE, tmp_bson ("{'$db': 'db', 'count': 'collection', 'opt': 1}")); - - reply_to_request_simple (request, "{'ok': 1, 'n': 1}"); - ASSERT_OR_PRINT (1 == future_get_int64_t (future), error); - - request_destroy (request); - future_destroy (future); - mongoc_collection_destroy (collection); - mongoc_client_destroy (client); - mock_server_destroy (server); -} - - -static void -test_count_with_collation (void) -{ - mock_server_t *server; - mongoc_collection_t *collection; - mongoc_client_t *client; - future_t *future; - request_t *request; - bson_error_t error; - - server = mock_server_with_auto_hello (WIRE_VERSION_MIN); - mock_server_run (server); - - client = test_framework_client_new_from_uri (mock_server_get_uri (server), NULL); - collection = mongoc_client_get_collection (client, "db", "collection"); - - future = future_collection_count_with_opts ( - collection, MONGOC_QUERY_SECONDARY_OK, NULL, 0, 0, tmp_bson ("{'collation': {'locale': 'en'}}"), NULL, &error); - - request = mock_server_receives_msg (server, - MONGOC_MSG_NONE, - tmp_bson ("{'$db': 'db'," - " 'count': 'collection'," - " 'collation': {'locale': 'en'}}")); - reply_to_request_simple (request, "{'ok': 1, 'n': 1}"); - ASSERT_OR_PRINT (1 == future_get_int64_t (future), error); - request_destroy (request); - - - future_destroy (future); - mongoc_collection_destroy (collection); - mongoc_client_destroy (client); - mock_server_destroy (server); -} - - static void test_count_documents (void) { @@ -5717,17 +5341,6 @@ test_collection_install (TestSuite *suite) TestSuite_AddLive (suite, "/Collection/remove/multi", test_remove_multi); TestSuite_AddFull ( suite, "/Collection/remove/oversize", test_remove_oversize, NULL, NULL, test_framework_skip_if_slow_or_live); - TestSuite_AddLive (suite, "/Collection/count", test_count); - TestSuite_AddMockServerTest (suite, "/Collection/count_with_opts", test_count_with_opts); - TestSuite_AddMockServerTest (suite, "/Collection/count/read_pref", test_count_read_pref); - TestSuite_AddMockServerTest (suite, "/Collection/count/read_concern", test_count_read_concern); - TestSuite_AddMockServerTest (suite, "/Collection/count/collation", test_count_with_collation); - TestSuite_AddFull (suite, - "/Collection/count/read_concern_live", - test_count_read_concern_live, - NULL, - NULL, - mongod_supports_majority_read_concern); TestSuite_AddLive (suite, "/Collection/drop", test_drop); TestSuite_AddLive (suite, "/Collection/aggregate", test_aggregate); TestSuite_AddMockServerTest (suite, "/Collection/aggregate/inherit/collection", test_aggregate_inherit_collection); diff --git a/src/libmongoc/tests/test-mongoc-hedged-reads.c b/src/libmongoc/tests/test-mongoc-hedged-reads.c index 642c10815a5..e6b4864c69d 100644 --- a/src/libmongoc/tests/test-mongoc-hedged-reads.c +++ b/src/libmongoc/tests/test-mongoc-hedged-reads.c @@ -49,7 +49,7 @@ test_mongos_hedged_reads_read_pref (void) * readPreference. */ mongoc_collection_set_read_prefs (collection, prefs); - future = future_collection_count (collection, MONGOC_QUERY_NONE, NULL, 0, 0, NULL, &error); + future = future_collection_estimated_document_count (collection, NULL, prefs, NULL, &error); request = mock_server_receives_msg (server, MONGOC_MSG_NONE, tmp_bson ("{'$db': 'db'," @@ -68,7 +68,7 @@ test_mongos_hedged_reads_read_pref (void) mongoc_read_prefs_set_hedge (prefs, &hedge_doc); mongoc_collection_set_read_prefs (collection, prefs); - future = future_collection_count (collection, MONGOC_QUERY_NONE, NULL, 0, 0, NULL, &error); + future = future_collection_estimated_document_count (collection, NULL, prefs, NULL, &error); request = mock_server_receives_msg (server, MONGOC_MSG_NONE, tmp_bson ("{'$db': 'db'," diff --git a/src/libmongoc/tests/test-mongoc-max-staleness.c b/src/libmongoc/tests/test-mongoc-max-staleness.c index a812235e306..da7945bc488 100644 --- a/src/libmongoc/tests/test-mongoc-max-staleness.c +++ b/src/libmongoc/tests/test-mongoc-max-staleness.c @@ -117,7 +117,7 @@ test_mongos_max_staleness_read_pref (void) /* count command with mode "secondary", no MONGOC_URI_MAXSTALENESSSECONDS. */ prefs = mongoc_read_prefs_new (MONGOC_READ_SECONDARY); mongoc_collection_set_read_prefs (collection, prefs); - future = future_collection_count (collection, MONGOC_QUERY_NONE, NULL, 0, 0, NULL, &error); + future = future_collection_estimated_document_count (collection, NULL, NULL, NULL, &error); request = mock_server_receives_msg (server, MONGOC_MSG_NONE, tmp_bson ("{'$db': 'db'," @@ -137,7 +137,7 @@ test_mongos_max_staleness_read_pref (void) mongoc_collection_set_read_prefs (collection, prefs); mongoc_collection_set_read_prefs (collection, prefs); - future = future_collection_count (collection, MONGOC_QUERY_NONE, NULL, 0, 0, NULL, &error); + future = future_collection_estimated_document_count (collection, NULL, NULL, NULL, &error); request = mock_server_receives_msg (server, MONGOC_MSG_NONE, tmp_bson ("{'$db': 'db'," @@ -157,7 +157,7 @@ test_mongos_max_staleness_read_pref (void) mongoc_read_prefs_set_max_staleness_seconds (prefs, MONGOC_NO_MAX_STALENESS); mongoc_collection_set_read_prefs (collection, prefs); - future = future_collection_count (collection, MONGOC_QUERY_NONE, NULL, 0, 0, NULL, &error); + future = future_collection_estimated_document_count (collection, NULL, NULL, NULL, &error); request = mock_server_receives_msg ( server, MONGOC_MSG_NONE, tmp_bson ("{'$db': 'db', '$readPreference': {'mode': 'secondaryPreferred'}}")); @@ -172,7 +172,7 @@ test_mongos_max_staleness_read_pref (void) mongoc_read_prefs_set_max_staleness_seconds (prefs, 1); mongoc_collection_set_read_prefs (collection, prefs); - future = future_collection_count (collection, MONGOC_QUERY_NONE, NULL, 0, 0, NULL, &error); + future = future_collection_estimated_document_count (collection, NULL, NULL, NULL, &error); request = mock_server_receives_msg (server, MONGOC_MSG_NONE, tmp_bson ("{'$db': 'db'," diff --git a/src/libmongoc/tests/test-mongoc-opts.c b/src/libmongoc/tests/test-mongoc-opts.c index 723916e34fb..a96ca5686a4 100644 --- a/src/libmongoc/tests/test-mongoc-opts.c +++ b/src/libmongoc/tests/test-mongoc-opts.c @@ -424,15 +424,6 @@ collection_watch (func_ctx_t *ctx, bson_t *cmd) } -static future_t * -count (func_ctx_t *ctx, bson_t *cmd) -{ - BSON_APPEND_UTF8 (cmd, "count", "collection"); - return future_collection_count_with_opts ( - ctx->collection, MONGOC_QUERY_NONE, NULL, 0, 0, ctx->opts, ctx->prefs, &ctx->error); -} - - static future_t * count_documents (func_ctx_t *ctx, bson_t *cmd) { @@ -840,8 +831,6 @@ static opt_inheritance_test_t gInheritanceTests[] = { OPT_TEST (COLL, collection_read_write_cmd, WRITE_CONCERN), OPT_TEST (COLL, collection_watch, READ_CONCERN), OPT_TEST (COLL, collection_write_cmd, WRITE_CONCERN), - OPT_TEST (COLL, count, READ_CONCERN), - OPT_TEST (COLL, count, READ_PREFS), OPT_TEST (COLL, count_documents, READ_CONCERN), OPT_TEST (COLL, count_documents, READ_PREFS), OPT_TEST (COLL, create_index, WRITE_CONCERN), diff --git a/src/libmongoc/tests/test-mongoc-read-concern.c b/src/libmongoc/tests/test-mongoc-read-concern.c index 775fd9f1e21..fc121bb578f 100644 --- a/src/libmongoc/tests/test-mongoc-read-concern.c +++ b/src/libmongoc/tests/test-mongoc-read-concern.c @@ -164,18 +164,6 @@ _test_read_concern_wire_version (bool explicit) future_destroy (future); - /* - * count - */ - future = - future_collection_count_with_opts (collection, MONGOC_QUERY_NONE, tmp_bson ("{}"), 0, 0, &opts, NULL, &error); - request = - mock_server_receives_msg (server, MONGOC_MSG_NONE, tmp_bson ("{'$db': 'db', 'readConcern': {'level': 'foo'}}")); - reply_to_request_simple (request, "{'ok': 1, 'n': 1}"); - request_destroy (request); - ASSERT_CMPINT64 (future_get_int64_t (future), ==, (int64_t) 1); - - future_destroy (future); mongoc_cursor_destroy (cursor); mongoc_collection_destroy (collection); mongoc_client_destroy (client); From 7e043234cd289f96ff914d0a11217c047a7ab974 Mon Sep 17 00:00:00 2001 From: Kevin Albertson Date: Mon, 31 Mar 2025 11:28:02 -0400 Subject: [PATCH 2/4] restore NEWS of removals Was accidentally removed in 1b6b6d453310a0c601fde46395fcfb1c084a526b --- NEWS | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/NEWS b/NEWS index e337b3e5be5..35383ea70cf 100644 --- a/NEWS +++ b/NEWS @@ -92,6 +92,10 @@ Unreleased (2.0.0) * `mongoc_collection_insert_many` * `mongoc_bulkwrite_t` * `mongoc_bulk_operation_t` + * `mongoc_bulk_operation_delete` is removed. Use `mongoc_bulk_operation_remove()` instead. + * `mongoc_bulk_operation_delete_one` is removed. Use `mongoc_bulk_operation_remove_one` instead. + * `mongoc_bulk_operation_get_hint` is removed. Use `mongoc_bulk_operation_get_server_id` instead. + * `mongoc_bulk_operation_set_hint` is removed. Use `mongoc_bulk_operation_set_server_id` instead. * `mongoc_collection_count` and `mongoc_collection_count_with_opts` are removed. Use `mongoc_collection_count_documents` or `mongoc_collection_estimated_document_count` instead. * `mongoc_collection_stats` is removed. Use the [$collStats aggregation pipeline stage](https://www.mongodb.com/docs/manual/reference/operator/aggregation/collStats/) with `mongoc_collection_aggregate` instead. * `mongoc_collection_validate` is removed. Run the [validate](https://www.mongodb.com/docs/manual/reference/command/validate/) command directly with `mongoc_client_read_command_with_opts` instead. From 7d526761b9574ab88d38d6d9cea5ccb19cfd10a5 Mon Sep 17 00:00:00 2001 From: Kevin Albertson Date: Tue, 1 Apr 2025 08:43:13 -0400 Subject: [PATCH 3/4] use `mongoc_collection_read_command_with_opts` in test to emulate deprecated count Enables retryable write behavior --- src/libmongoc/tests/json-test-operations.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/libmongoc/tests/json-test-operations.c b/src/libmongoc/tests/json-test-operations.c index 5af9c2469ba..5baaeb0e2e8 100644 --- a/src/libmongoc/tests/json-test-operations.c +++ b/src/libmongoc/tests/json-test-operations.c @@ -1234,7 +1234,7 @@ count (mongoc_collection_t *collection, bson_t *cmd = BCON_NEW ("count", mongoc_collection_get_name (collection)); BSON_ASSERT (BSON_APPEND_DOCUMENT (cmd, "query", &filter)); BSON_ASSERT (bson_concat (cmd, &opts)); - bool ok = mongoc_collection_command_simple (collection, cmd, read_prefs, reply, &error); + bool ok = mongoc_collection_read_command_with_opts (collection, cmd, read_prefs, NULL, reply, &error); if (!ok) { // Set resulting count to -1 to indicate failure. r = -1; From 995eb64534e0c4c97359c0b9adb113dbd8630681 Mon Sep 17 00:00:00 2001 From: Kevin Albertson Date: Tue, 1 Apr 2025 09:02:56 -0400 Subject: [PATCH 4/4] fix handling of opts --- src/libmongoc/tests/json-test-operations.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/libmongoc/tests/json-test-operations.c b/src/libmongoc/tests/json-test-operations.c index 5baaeb0e2e8..04885f07a3c 100644 --- a/src/libmongoc/tests/json-test-operations.c +++ b/src/libmongoc/tests/json-test-operations.c @@ -1233,8 +1233,7 @@ count (mongoc_collection_t *collection, // Run the "count" command directly to support tests. See: CRUD spec "Count API Details". bson_t *cmd = BCON_NEW ("count", mongoc_collection_get_name (collection)); BSON_ASSERT (BSON_APPEND_DOCUMENT (cmd, "query", &filter)); - BSON_ASSERT (bson_concat (cmd, &opts)); - bool ok = mongoc_collection_read_command_with_opts (collection, cmd, read_prefs, NULL, reply, &error); + bool ok = mongoc_collection_read_command_with_opts (collection, cmd, read_prefs, &opts, reply, &error); if (!ok) { // Set resulting count to -1 to indicate failure. r = -1;