1MONGOC_COLLECTION_ESTIMATED_DOCUMEMNOTlN_iGCbOOmCUo_NnCTgO(oL3cL)ECTION_ESTIMATED_DOCUMENT_COUNT(3)
2
3
4

NAME

6       mongoc_collection_estimated_document_count   -  mongoc_collection_esti‐
7       mated_document_count()
8

SYNOPSIS

10          int64_t
11          mongoc_collection_estimated_document_count (mongoc_collection_t *collection,
12                                                      const bson_t *opts,
13                                                      const mongoc_read_prefs_t *read_prefs,
14                                                      bson_t *reply,
15                                                      bson_error_t *error);
16

PARAMETERS

18collection: A mongoc_collection_t.
19
20opts: A bson_t, NULL to ignore.
21
22read_prefs: A mongoc_read_prefs_t or NULL.
23
24reply: A location for an uninitialized bson_t to  store  the  command
25         reply, NULL to ignore. If not NULL, reply will be initialized.
26
27error: An optional location for a bson_error_t or NULL.
28
29       opts may be NULL or a BSON document with additional command options:
30
31readConcern:    Construct    a    mongoc_read_concern_t    and    use
32         mongoc_read_concern_append() to add the read concern to opts. See the
33         example code for mongoc_client_read_command_with_opts(). Read concern
34         requires MongoDB 3.2 or later, otherwise an error is returned.
35
36sessionId:   First,   construct   a   mongoc_client_session_t    with
37         mongoc_client_start_session().  You  can  begin  a  transaction  with
38         mongoc_client_session_start_transaction(),    optionally    with    a
39         mongoc_transaction_opt_t  that  overrides  the options inherited from
40         collection, and use mongoc_client_session_append() to add the session
41         to opts. See the example code for mongoc_client_session_t.
42
43collation:  Configure  textual comparisons. See Setting Collation Or‐
44         der, and the MongoDB Manual entry on  Collation.  Collation  requires
45         MongoDB 3.2 or later, otherwise an error is returned.
46
47serverId:  To  target  a specific server, include an int32 "serverId"
48         field. Obtain the id by calling  mongoc_client_select_server(),  then
49         mongoc_server_description_id() on its return value.
50
51skip:  An int specifying how many documents matching the query should
52         be skipped before counting.
53
54limit: An int specifying the maximum number of documents to count.
55
56comment: A bson_value_t specifying the comment to attach to this com‐
57         mand.  The  comment will appear in log messages, profiler output, and
58         currentOp output. Requires MongoDB 4.4 or later.
59
60       For a list of all options, see the MongoDB Manual entry  on  the  count
61       command.
62

DESCRIPTION

64       This  functions  executes a count query on collection. In contrast with
65       mongoc_collection_count_documents(), the count returned is not  guaran‐
66       teed to be accurate.
67
68       This  function  is considered a retryable read operation.  Upon a tran‐
69       sient error (a network error, errors due to replica set failover, etc.)
70       the  operation  is  safely retried once.  If retryreads is false in the
71       URI (see mongoc_uri_t) the retry behavior does not apply.
72
73   Behavior
74       This method is implemented using the count command. Due to an oversight
75       in  versions 5.0.0-5.0.8 of MongoDB, the count command was not included
76       in version "1" of the Stable API. Applications using this  method  with
77       the  Stable  API  are  recommended  to  upgrade their server version to
78       5.0.9+ or disable strict mode (via :symbol:`mongoc_server_api_strict())
79       to avoid encountering errors.
80

ERRORS

82       Errors are propagated via the error parameter.
83

RETURNS

85       -1 on failure, otherwise the number of documents counted.
86

EXAMPLE

88          #include <bson/bson.h>
89          #include <mongoc/mongoc.h>
90          #include <stdio.h>
91
92          static void
93          print_count (mongoc_collection_t *collection, bson_t *query)
94          {
95             bson_error_t error;
96             int64_t count;
97             bson_t* opts = BCON_NEW ("skip", BCON_INT64(5));
98
99             count = mongoc_collection_estimated_document_count (
100                collection, opts, NULL, NULL, &error);
101             bson_destroy (opts);
102
103             if (count < 0) {
104                fprintf (stderr, "Count failed: %s\n", error.message);
105             } else {
106                printf ("%" PRId64 " documents counted.\n", count);
107             }
108          }
109
110       SEE ALSO:
111          mongoc_collection_count_documents()
112          Count: Behavior in the MongoDB Manual
113
114

AUTHOR

116       MongoDB, Inc
117
119       2017-present, MongoDB, Inc
120
121
122
123
1241.23.1                           OMcOtNG2O0C,_C2O0L2L2ECTION_ESTIMATED_DOCUMENT_COUNT(3)
Impressum