1MONGOC_COLLECTION_ESTIMATED_DOCUMMoEnMNgOToN_DGCBOOCUC_NCTDO(rL3iL)vEeCrTION_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

ERRORS

62       Errors are propagated via the error parameter.
63

RETURNS

65       -1 on failure, otherwise the number of documents counted.
66

EXAMPLE

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

SEE ALSO

91       mongoc_collection_count_documents()
92

AUTHOR

94       MongoDB, Inc
95
97       2017-present, MongoDB, Inc
98
99
100
101
1021.13.1                           JMaOnNG2O4C,_C2O0L1L9ECTION_ESTIMATED_DOCUMENT_COUNT(3)
Impressum