1MONGOC_DATABASE_AGGREGATE(3)       libmongoc      MONGOC_DATABASE_AGGREGATE(3)
2
3
4

SYNOPSIS

6          mongoc_cursor_t *
7          mongoc_database_aggregate (mongoc_database_t *database,
8                                     const bson_t *pipeline,
9                                     const bson_t *opts,
10                                     const mongoc_read_prefs_t *read_prefs)
11             BSON_GNUC_WARN_UNUSED_RESULT;
12

PARAMETERS

14database: A mongoc_database_t.
15
16pipeline: A bson_t, either a BSON array or a BSON document containing
17         an array field named "pipeline".
18
19opts: A bson_t containing options for the command, or NULL.
20
21read_prefs: A mongoc_read_prefs_t or NULL.
22
23       opts may be NULL or a BSON document with additional command options:
24
25readConcern:    Construct    a    mongoc_read_concern_t    and    use
26         mongoc_read_concern_append() to add the read concern to opts. See the
27         example code for mongoc_client_read_command_with_opts(). Read concern
28         requires MongoDB 3.2 or later, otherwise an error is returned.
29
30writeConcern:    Construct    a    mongoc_write_concern_t   and   use
31         mongoc_write_concern_append() to add the write concern to  opts.  See
32         the example code for mongoc_client_write_command_with_opts().
33
34sessionId:    First,   construct   a   mongoc_client_session_t   with
35         mongoc_client_start_session().  You  can  begin  a  transaction  with
36         mongoc_client_session_start_transaction(),    optionally    with    a
37         mongoc_transaction_opt_t that overrides the  options  inherited  from
38         database,  and  use mongoc_client_session_append() to add the session
39         to opts. See the example code for mongoc_client_session_t.
40
41bypassDocumentValidation: Set to true to skip server-side schema val‐
42         idation of the provided BSON documents.
43
44collation:  Configure  textual comparisons. See Setting Collation Or‐
45         der, and the MongoDB Manual entry on  Collation.  Collation  requires
46         MongoDB 3.2 or later, otherwise an error is returned.
47
48serverId:  To  target  a specific server, include an int32 "serverId"
49         field. Obtain the id by calling  mongoc_client_select_server(),  then
50         mongoc_server_description_id() on its return value.
51
52batchSize:  An int32 representing number of documents requested to be
53         returned on each call to mongoc_cursor_next()
54
55let: A BSON document consisting of any  number  of  parameter  names,
56         each  followed  by  definitions of constants in the MQL Aggregate Ex‐
57         pression language.
58
59comment: A bson_value_t specifying the comment to attach to this com‐
60         mand.  The  comment will appear in log messages, profiler output, and
61         currentOp output. Only string values are supported prior  to  MongoDB
62         4.4.
63
64hint: A document or string that specifies the index to use to support
65         the query predicate.
66
67       For a list of all options, see the MongoDB Manual entry on  the  aggre‐
68       gate command.
69

DESCRIPTION

71       This function creates a cursor which sends the aggregate command on the
72       underlying database upon the first call  to  mongoc_cursor_next().  For
73       more  information  on  building  aggregation pipelines, see the MongoDB
74       Manual entry on the aggregate command.  Note  that  the  pipeline  must
75       start  with a compatible stage that does not require an underlying col‐
76       lection (e.g. "$currentOp", "$listLocalSessions").
77
78       Read preferences, read and write concern, and collation can be overrid‐
79       den  by various sources. The highest-priority sources for these options
80       are listed first in the following table. In a transaction, read concern
81       and  write  concern are prohibited in opts and the read preference must
82       be primary or NULL. Write concern is applied from opts, or if opts  has
83       no  write  concern  and  the  aggregation pipeline includes "$out", the
84       write concern is applied from database.
85
86            ┌─────────────────┬──────────────┬───────────────┬───────────┐
87            │Read Preferences │ Read Concern │ Write Concern │ Collation │
88            ├─────────────────┼──────────────┼───────────────┼───────────┤
89read_prefs       opts         opts          opts      
90            ├─────────────────┼──────────────┼───────────────┼───────────┤
91            │Transaction      │ Transaction  │ Transaction   │           │
92            ├─────────────────┼──────────────┼───────────────┼───────────┤
93database         database     database      │           │
94            └─────────────────┴──────────────┴───────────────┴───────────┘
95
96       See the example for transactions and for the  "distinct"  command  with
97       opts.
98
99       This function is considered a retryable read operation unless the pipe‐
100       line contains a write stage like $out or $merge.  Upon a transient  er‐
101       ror (a network error, errors due to replica set failover, etc.) the op‐
102       eration is safely retried once.  If retryreads is false in the URI (see
103       mongoc_uri_t) the retry behavior does not apply.
104

RETURNS

106       This  function returns a newly allocated mongoc_cursor_t that should be
107       freed with mongoc_cursor_destroy() when no longer in use. The  returned
108       mongoc_cursor_t  is  never  NULL,  even  on  error.  The user must call
109       mongoc_cursor_next() on the returned  mongoc_cursor_t  to  execute  the
110       initial command.
111
112       Cursor  errors  can  be checked with mongoc_cursor_error_document(). It
113       always fills out the bson_error_t if an error occurred, and  optionally
114       includes a server reply document if the error occurred server-side.
115
116       WARNING:
117          Failure  to  handle the result of this function is a programming er‐
118          ror.
119

EXAMPLE

121          #include <bson/bson.h>
122          #include <mongoc/mongoc.h>
123
124          static mongoc_cursor_t *
125          current_op_query (mongoc_client_t *client)
126          {
127             mongoc_cursor_t *cursor;
128             mongoc_database_t *database;
129             bson_t *pipeline;
130
131             pipeline = BCON_NEW ("pipeline",
132                                  "[",
133                                  "{",
134                                  "$currentOp",
135                                  "{",
136                                  "}",
137                                  "}",
138                                  "]");
139
140             /* $currentOp must be run on the admin database */
141             database = mongoc_client_get_database (client, "admin");
142
143             cursor = mongoc_database_aggregate (
144                database, pipeline, NULL, NULL);
145
146             bson_destroy (pipeline);
147             mongoc_database_destroy (database);
148
149             return cursor;
150          }
151

AUTHOR

153       MongoDB, Inc
154
156       2017-present, MongoDB, Inc
157
158
159
160
1611.25.1                           Nov 08, 2023     MONGOC_DATABASE_AGGREGATE(3)
Impressum