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

18       · collection: A mongoc_collection_t.
19
20       · opts: A bson_t, NULL to ignore.
21
22       · read_prefs: A mongoc_read_prefs_t or NULL.
23
24       · reply: A location for an uninitialized bson_t to  store  the  command
25         reply, NULL to ignore. If not NULL, reply will be initialized.
26
27       · error: 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
31       · readConcern:   Construct   a   mongoc_read_concern_t   and  use  mon‐
32         goc_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
36       · sessionId:  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
43       · collation:  Configure  textual  comparisons.  See  Setting  Collation
44         Order, and the MongoDB Manual entry on Collation. Collation  requires
45         MongoDB 3.2 or later, otherwise an error is returned.
46
47       · serverId:  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
51       · skip:  An int specifying how many documents matching the query should
52         be skipped before counting.
53
54       · limit: 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

SEE ALSO

96       mongoc_collection_count_documents()
97

AUTHOR

99       MongoDB, Inc
100
102       2017-present, MongoDB, Inc
103
104
105
106
1071.16.2                           FMeObNG2O5C,_C2O0L2L0ECTION_ESTIMATED_DOCUMENT_COUNT(3)
Impressum