Skip to content

Commit 279c7fe

Browse files
committed
CDRIVER-1526 Rewrite "_with_write_concern" functions to "_with_opts"
These function now take a generic bson_t options, which can contain whichever options or arguments to the command. To add write_concern to the these commands, add it to the generic opts with: mongoc_write_concern_append (wc, opts); And pass opts to the function. Removed - mongoc_collection_aggregate_with_opts - mongoc_database_create_collection_with_opts Their respective function without _with_opts had opts parameter that was retrofitted to support writeConcern and other arbitrary options
1 parent 1232046 commit 279c7fe

31 files changed

+627
-601
lines changed

build/autotools/versions.ldscript

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -332,7 +332,6 @@ LIBMONGOC_1.4 {
332332
mongoc_client_select_server;
333333
mongoc_client_set_apm_callbacks;
334334
mongoc_client_set_error_api;
335-
mongoc_collection_aggregate_with_write_concern;
336335
mongoc_cursor_get_limit;
337336
mongoc_cursor_new_from_command_reply;
338337
mongoc_cursor_set_hint;
@@ -416,13 +415,12 @@ LIBMONGOC_1.5 {
416415
mongoc_bulk_operation_update_one_with_opts;
417416
mongoc_client_pool_set_appname;
418417
mongoc_client_set_appname;
419-
mongoc_collection_create_index_with_write_concern;
420-
mongoc_collection_drop_index_with_write_concern;
421-
mongoc_collection_drop_with_write_concern;
418+
mongoc_collection_create_index_with_opts;
419+
mongoc_collection_drop_index_with_opts;
420+
mongoc_collection_drop_with_opts;
422421
mongoc_collection_find_with_opts;
423-
mongoc_collection_rename_with_write_concern;
424-
mongoc_database_create_collection_with_write_concern;
425-
mongoc_database_drop_with_write_concern;
422+
mongoc_collection_rename_with_opts;
423+
mongoc_database_drop_with_opts;
426424
mongoc_handshake_data_append;
427425
mongoc_topology_description_get_servers;
428426
mongoc_topology_description_has_readable_server;

build/cmake/libmongoc-ssl.def

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -135,21 +135,20 @@ mongoc_client_set_ssl_opts
135135
mongoc_client_set_stream_initiator
136136
mongoc_client_set_write_concern
137137
mongoc_collection_aggregate
138-
mongoc_collection_aggregate_with_write_concern
139138
mongoc_collection_command
140139
mongoc_collection_command_simple
141140
mongoc_collection_copy
142141
mongoc_collection_count
143142
mongoc_collection_count_with_opts
144143
mongoc_collection_create_bulk_operation
145144
mongoc_collection_create_index
146-
mongoc_collection_create_index_with_write_concern
145+
mongoc_collection_create_index_with_opts
147146
mongoc_collection_delete
148147
mongoc_collection_destroy
149148
mongoc_collection_drop
150149
mongoc_collection_drop_index
151-
mongoc_collection_drop_index_with_write_concern
152-
mongoc_collection_drop_with_write_concern
150+
mongoc_collection_drop_index_with_opts
151+
mongoc_collection_drop_with_opts
153152
mongoc_collection_ensure_index
154153
mongoc_collection_find
155154
mongoc_collection_find_and_modify
@@ -166,7 +165,7 @@ mongoc_collection_insert_bulk
166165
mongoc_collection_keys_to_index_string
167166
mongoc_collection_remove
168167
mongoc_collection_rename
169-
mongoc_collection_rename_with_write_concern
168+
mongoc_collection_rename_with_opts
170169
mongoc_collection_save
171170
mongoc_collection_set_read_concern
172171
mongoc_collection_set_read_prefs
@@ -197,10 +196,9 @@ mongoc_database_command
197196
mongoc_database_command_simple
198197
mongoc_database_copy
199198
mongoc_database_create_collection
200-
mongoc_database_create_collection_with_write_concern
201199
mongoc_database_destroy
202200
mongoc_database_drop
203-
mongoc_database_drop_with_write_concern
201+
mongoc_database_drop_with_opts
204202
mongoc_database_find_collections
205203
mongoc_database_get_collection
206204
mongoc_database_get_collection_names

build/cmake/libmongoc.def

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -133,21 +133,20 @@ mongoc_client_set_read_prefs
133133
mongoc_client_set_stream_initiator
134134
mongoc_client_set_write_concern
135135
mongoc_collection_aggregate
136-
mongoc_collection_aggregate_with_write_concern
137136
mongoc_collection_command
138137
mongoc_collection_command_simple
139138
mongoc_collection_copy
140139
mongoc_collection_count
141140
mongoc_collection_count_with_opts
142141
mongoc_collection_create_bulk_operation
143142
mongoc_collection_create_index
144-
mongoc_collection_create_index_with_write_concern
143+
mongoc_collection_create_index_with_opts
145144
mongoc_collection_delete
146145
mongoc_collection_destroy
147146
mongoc_collection_drop
148147
mongoc_collection_drop_index
149-
mongoc_collection_drop_index_with_write_concern
150-
mongoc_collection_drop_with_write_concern
148+
mongoc_collection_drop_index_with_opts
149+
mongoc_collection_drop_with_opts
151150
mongoc_collection_ensure_index
152151
mongoc_collection_find
153152
mongoc_collection_find_and_modify
@@ -164,7 +163,7 @@ mongoc_collection_insert_bulk
164163
mongoc_collection_keys_to_index_string
165164
mongoc_collection_remove
166165
mongoc_collection_rename
167-
mongoc_collection_rename_with_write_concern
166+
mongoc_collection_rename_with_opts
168167
mongoc_collection_save
169168
mongoc_collection_set_read_concern
170169
mongoc_collection_set_read_prefs
@@ -195,10 +194,9 @@ mongoc_database_command
195194
mongoc_database_command_simple
196195
mongoc_database_copy
197196
mongoc_database_create_collection
198-
mongoc_database_create_collection_with_write_concern
199197
mongoc_database_destroy
200198
mongoc_database_drop
201-
mongoc_database_drop_with_write_concern
199+
mongoc_database_drop_with_opts
202200
mongoc_database_find_collections
203201
mongoc_database_get_collection
204202
mongoc_database_get_collection_names

doc/mongoc_collection_aggregate.page

Lines changed: 79 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,12 @@
1616
<section id="synopsis">
1717
<title>Synopsis</title>
1818
<synopsis><code mime="text/x-csrc"><![CDATA[mongoc_cursor_t *
19-
mongoc_collection_aggregate (mongoc_collection_t *collection,
20-
mongoc_query_flags_t flags,
21-
const bson_t *pipeline,
22-
const bson_t *options,
23-
const mongoc_read_prefs_t *read_prefs)
19+
mongoc_collection_aggregate (
20+
mongoc_collection_t *collection,
21+
mongoc_query_flags_t flags,
22+
const bson_t *pipeline,
23+
const bson_t *opts,
24+
const mongoc_read_prefs_t *read_prefs)
2425
BSON_GNUC_WARN_UNUSED_RESULT;
2526
]]></code></synopsis>
2627
</section>
@@ -31,14 +32,85 @@ mongoc_collection_aggregate (mongoc_collection_t *collection,
3132
<tr><td><p>collection</p></td><td><p>A <code xref="mongoc_collection_t">mongoc_collection_t</code>.</p></td></tr>
3233
<tr><td><p>flags</p></td><td><p>A <code xref="mongoc_query_flags_t">mongoc_query_flags_t</code>.</p></td></tr>
3334
<tr><td><p>pipeline</p></td><td><p>A <code xref="bson:bson_t">bson_t</code> containing the pipeline array.</p></td></tr>
34-
<tr><td><p>options</p></td><td><p>A <code xref="bson:bson_t">bson_t</code> containing options for the pipeline, or <code>NULL</code>.</p></td></tr>
35+
<tr><td><p>opts</p></td><td><p>A <code xref="bson:bson_t">bson_t</code> containing options for the command, or <code>NULL</code>.</p></td></tr>
3536
<tr><td><p>read_prefs</p></td><td><p>A <code xref="mongoc_read_prefs_t">mongoc_read_prefs_t</code> or <code>NULL</code>.</p></td></tr>
37+
3638
</table>
3739
</section>
3840

3941
<section id="description">
4042
<title>Description</title>
41-
<p>For more information, see <code xref="mongoc_collection_aggregate_with_write_concern">mongoc_collection_aggregate_with_write_concern()</code>. This function is a thin wrapper, passing <code>NULL</code> in as <code xref="mongoc_write_concern_t">mongoc_write_concern_t</code> parameter.</p>
4243

44+
<p>This function shall execute an aggregation query on the underlying 'collection'. The bson 'pipeline' is not validated, simply passed along as appropriate to the server. As such, compatibility and errors should be validated in the appropriate server documentation.</p>
45+
46+
<p>In the case of older server versions, &lt; v2.5, the returned cursor is a synthetic iterator over the result set. This provides a limitation insofar as returned documents can be no larger than 16MB. When connecting to newer servers this limitation doesn't exist. The specific test is for wire_version &gt; 0.</p>
47+
48+
<p>For more information on building MongoDB pipelines, see <link href="http://docs.mongodb.org/manual/reference/command/aggregate/">MongoDB Aggregation Command</link> on the MongoDB website.</p>
49+
<note style="info"><p>The <code>pipeline</code> parameter should contain a field named <code>pipeline</code> containing a BSON array of pipeline stages.</p></note>
50+
<note style="tip"><p>The <code xref="mongoc_read_concern_t">mongoc_read_concern_t</code> and the <code xref="mongoc_write_concern_t">mongoc_write_concern_t</code> specified on the <code xref="mongoc_collection_t">mongoc_collection_t</code> will be used, if any.</p></note>
51+
</section>
52+
53+
<section id="return">
54+
<title>Returns</title>
55+
<p>This function returns a newly allocated <code xref="mongoc_cursor_t">mongoc_cursor_t</code> that should be freed with <code xref="mongoc_cursor_destroy">mongoc_cursor_destroy()</code> when no longer in use. The returned <code xref="mongoc_cursor_t">mongoc_cursor_t</code> is never <code>NULL</code>; if the parameters are invalid, the <code xref="bson:bson_error_t">bson_error_t</code> in the <code xref="mongoc_cursor_t">mongoc_cursor_t</code> is filled out, and the <code xref="mongoc_cursor_t">mongoc_cursor_t</code> is returned before the server is selected.</p>
56+
<note style="warning"><p>Failure to handle the result of this function is a programming error.</p></note>
57+
</section>
58+
59+
<section id="example">
60+
<title>Example</title>
61+
<listing>
62+
<title>Aggregation Example</title>
63+
<code mime="text/x-csrc"><![CDATA[
64+
#include <bcon.h>
65+
#include <mongoc.h>
66+
67+
static mongoc_cursor_t *
68+
pipeline_query (mongoc_collection_t *collection)
69+
{
70+
mongoc_cursor_t *cursor;
71+
bson_t *pipeline;
72+
73+
pipeline = BCON_NEW ("pipeline", "[",
74+
"{", "$match", "{", "foo", BCON_UTF8 ("A"), "}", "}",
75+
"{", "$match", "{", "bar", BCON_BOOL (false), "}", "}",
76+
"]");
77+
78+
cursor = mongoc_collection_aggregate (collection,
79+
MONGOC_QUERY_NONE,
80+
pipeline,
81+
NULL,
82+
NULL,
83+
NULL);
84+
85+
bson_destroy (pipeline);
86+
87+
return cursor;
88+
}]]></code>
89+
</listing>
4390
</section>
91+
92+
<section id="opts">
93+
<title>Other Parameters</title>
94+
<p>When using <code>$out</code>, the pipeline stage that writes, the write_concern field of the <code xref="mongoc_cursor_t">mongoc_cursor_t</code> will be set to the <code xref="mongoc_write_concern_t">mongoc_write_concern_t</code> parameter, if it is valid, and applied to the write command when <code xref="mongoc_cursor_next">mongoc_cursor_next()</code> is called. Pass any other parameters to the <code>aggregate</code> command, besides <code>pipeline</code>, as fields in <code>opts</code>:</p>
95+
<listing>
96+
<code mime="text/x-csrc"><![CDATA[
97+
mongoc_write_concern_t *write_concern = mongoc_write_concern_new ();
98+
mongoc_write_concern_set_w (write_concern, 3);
99+
100+
pipeline = BCON_NEW ("pipeline", "[",
101+
"{", "$out", BCON_UTF8 ("collection2"), "}",
102+
"]");
103+
104+
opts = BCON_NEW ("bypassDocumentValidation", BCON_BOOL (true));
105+
mongoc_write_concern_append (write_concern, opts);
106+
107+
cursor = mongoc_collection_aggregate (collection1,
108+
MONGOC_QUERY_NONE,
109+
pipeline,
110+
opts,
111+
NULL);
112+
]]></code>
113+
</listing>
114+
</section>
115+
44116
</page>

doc/mongoc_collection_aggregate_with_write_concern.page

Lines changed: 0 additions & 117 deletions
This file was deleted.

doc/mongoc_collection_create_index.page

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ mongoc_collection_create_index (mongoc_collection_t *collection,
3636

3737
<section id="description">
3838
<title>Description</title>
39-
<p>For more information, see <code xref="mongoc_collection_create_index_with_write_concern">mongoc_collection_create_index_with_write_concern()</code>. This function is a thin wrapper, passing <code>NULL</code> in as <code xref="mongoc_write_concern_t">mongoc_write_concern_t</code> parameter. This function also creates a local <code xref="bson:bson_t">bson_t</code> to pass in as <code>reply</code> parameter, destroying it afterward.</p>
39+
<p>For more information, see <code xref="mongoc_collection_create_index_with_opts">mongoc_collection_create_index_with_opts()</code>. This function is a thin wrapper, passing <code>NULL</code> in as <code xref="mongoc_write_concern_t">mongoc_write_concern_t</code> parameter. This function also creates a local <code xref="bson:bson_t">bson_t</code> to pass in as <code>reply</code> parameter, destroying it afterward.</p>
4040
</section>
4141

4242
</page>

0 commit comments

Comments
 (0)