1MONGOC_COLLECTION_COUNT(3)     MongoDB C Driver     MONGOC_COLLECTION_COUNT(3)
2
3
4

NAME

6       mongoc_collection_count - mongoc_collection_count()
7

DEPRECATED

9       This  function  is  deprecated and should not be used in new code.  Use
10       mongoc_collection_count_documents or  mongoc_collection_estimated_docu‐
11       ment_count instead.
12
13       mongoc_collection_count_documents  has  similar  performance to calling
14       mongoc_collection_count with a non-NULL query,  and  is  guaranteed  to
15       retrieve  an  accurate  collection count. See migrating from deprecated
16       count functions for details.
17
18       mongoc_collection_estimated_document_count has the same performance  as
19       calling  mongoc_collection_count  with a NULL query, but is not guaran‐
20       teed to retrieve an accurate collection count.
21

SYNOPSIS

23          int64_t
24          mongoc_collection_count (mongoc_collection_t *collection,
25                                   mongoc_query_flags_t flags,
26                                   const bson_t *query,
27                                   int64_t skip,
28                                   int64_t limit,
29                                   const mongoc_read_prefs_t *read_prefs,
30                                   bson_error_t *error)
31           BSON_GNUC_DEPRECATED_FOR (mongoc_collection_count_documents or
32                                     mongoc_collection_estimated_document_count);
33

PARAMETERS

35       · collection: A mongoc_collection_t.
36
37       · flags: A mongoc_query_flags_t.
38
39       · query: A bson_t containing the query.
40
41       · skip: A int64_t, zero to ignore.
42
43       · limit: A int64_t, zero to ignore.
44
45       · read_prefs: A mongoc_read_prefs_t or NULL.
46
47       · error: An optional location for a bson_error_t or NULL.
48

DESCRIPTION

50       This function shall execute a count query on  the  underlying  'collec‐
51       tion'. The bson 'query' is not validated, simply passed along as appro‐
52       priate to the server.  As such, compatibility and errors should be val‐
53       idated in the appropriate server documentation.
54
55       For more information, see the query reference at the MongoDB website.
56
57       The  mongoc_read_concern_t specified on the mongoc_collection_t will be
58       used, if any. If read_prefs is NULL, the collection's read  preferences
59       are used.
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_query_count (mongoc_collection_t *collection, bson_t *query)
74          {
75             bson_error_t error;
76             int64_t count;
77
78             count = mongoc_collection_count (
79                collection, MONGOC_QUERY_NONE, query, 0, 0, NULL, &error);
80
81             if (count < 0) {
82                fprintf (stderr, "Count failed: %s\n", error.message);
83             } else {
84                printf ("%" PRId64 " documents counted.\n", count);
85             }
86          }
87

AUTHOR

89       MongoDB, Inc
90
92       2017-present, MongoDB, Inc
93
94
95
96
971.13.1                           Jan 24, 2019       MONGOC_COLLECTION_COUNT(3)
Impressum