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  mon‐
32         goc_read_concern_append to add the read concern to opts. See the  ex‐
33         ample code for mongoc_client_read_command_with_opts. Read concern re‐
34         quires MongoDB 3.2 or later, otherwise an error is returned.
35
36sessionId:  First,  construct  a  mongoc_client_session_t  with  mon‐
37         goc_client_start_session.  You  can  begin  a  transaction  with mon‐
38         goc_client_session_start_transaction, optionally with a mongoc_trans‐
39         action_opt_t  that  overrides  the options inherited from collection,
40         and use mongoc_client_session_append to add the session to opts.  See
41         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

DESCRIPTION

57       This functions executes a count query on collection. In  contrast  with
58       mongoc_collection_count_documents(),  the count returned is not guaran‐
59       teed to be accurate.
60
61       This function is considered a retryable read operation.  Upon  a  tran‐
62       sient error (a network error, errors due to replica set failover, etc.)
63       the operation is safely retried once.  If retryreads is  false  in  the
64       URI (see mongoc_uri_t) the retry behavior does not apply.
65

ERRORS

67       Errors are propagated via the error parameter.
68

RETURNS

70       -1 on failure, otherwise the number of documents counted.
71

EXAMPLE

73          #include <bson/bson.h>
74          #include <mongoc/mongoc.h>
75          #include <stdio.h>
76
77          static void
78          print_count (mongoc_collection_t *collection, bson_t *query)
79          {
80             bson_error_t error;
81             int64_t count;
82             bson_t* opts = BCON_NEW ("skip", BCON_INT64(5));
83
84             count = mongoc_collection_estimated_document_count (
85                collection, opts, NULL, NULL, &error);
86             bson_destroy (opts);
87
88             if (count < 0) {
89                fprintf (stderr, "Count failed: %s\n", error.message);
90             } else {
91                printf ("%" PRId64 " documents counted.\n", count);
92             }
93          }
94
95       SEE ALSO:
96          mongoc_collection_count_documents()
97
98

AUTHOR

100       MongoDB, Inc
101
103       2017-present, MongoDB, Inc
104
105
106
107
1081.21.1                           MMaOrNG0O2C,_C2O0L2L2ECTION_ESTIMATED_DOCUMENT_COUNT(3)
Impressum