Skip to content

CDRIVER-4010 support 'let' option for aggregate command #810

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 3, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion build/generate-opts.py
Original file line number Diff line number Diff line change
Expand Up @@ -320,7 +320,8 @@ def __init__(self, items, **defaults):
bypass_option,
collation_option,
server_option,
('batchSize', {'type': 'int32_t', 'help': 'An ``int32`` representing number of documents requested to be returned on each call to :symbol:`mongoc_cursor_next`', 'check_set': True})
('batchSize', {'type': 'int32_t', 'help': 'An ``int32`` representing number of documents requested to be returned on each call to :symbol:`mongoc_cursor_next`', 'check_set': True}),
('let', {'type': 'document', 'help': 'A BSON document consisting of any number of parameter names, each followed by definitions of constants in the MQL Aggregate Expression language'})
])),

('mongoc_find_and_modify_appended_opts_t', Struct([
Expand Down
1 change: 1 addition & 0 deletions src/libmongoc/doc/includes/aggregate-opts.txt
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,4 @@
* ``collation``: Configure textual comparisons. See :ref:`Setting Collation Order <setting_collation_order>`, and `the MongoDB Manual entry on Collation <https://docs.mongodb.com/manual/reference/collation/>`_. Collation requires MongoDB 3.2 or later, otherwise an error is returned.
* ``serverId``: To target a specific server, include an int32 "serverId" field. Obtain the id by calling :symbol:`mongoc_client_select_server`, then :symbol:`mongoc_server_description_id` on its return value.
* ``batchSize``: An ``int32`` representing number of documents requested to be returned on each call to :symbol:`mongoc_cursor_next`
* ``let``: A BSON document consisting of any number of parameter names, each followed by definitions of constants in the MQL Aggregate Expression language
1 change: 1 addition & 0 deletions src/libmongoc/src/mongoc/mongoc-opts-private.h
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,7 @@ typedef struct _mongoc_aggregate_opts_t {
uint32_t serverId;
int32_t batchSize;
bool batchSize_is_set;
bson_t let;
bson_t extra;
} mongoc_aggregate_opts_t;

Expand Down
11 changes: 11 additions & 0 deletions src/libmongoc/src/mongoc/mongoc-opts.c
Original file line number Diff line number Diff line change
Expand Up @@ -1885,6 +1885,7 @@ _mongoc_aggregate_opts_parse (
mongoc_aggregate_opts->serverId = 0;
mongoc_aggregate_opts->batchSize = 0;
mongoc_aggregate_opts->batchSize_is_set = false;
bson_init (&mongoc_aggregate_opts->let);
bson_init (&mongoc_aggregate_opts->extra);

if (!opts) {
Expand Down Expand Up @@ -1967,6 +1968,15 @@ _mongoc_aggregate_opts_parse (

mongoc_aggregate_opts->batchSize_is_set = true;
}
else if (!strcmp (bson_iter_key (&iter), "let")) {
if (!_mongoc_convert_document (
client,
&iter,
&mongoc_aggregate_opts->let,
error)) {
return false;
}
}
else {
/* unrecognized values are copied to "extra" */
if (!BSON_APPEND_VALUE (
Expand All @@ -1993,6 +2003,7 @@ _mongoc_aggregate_opts_cleanup (mongoc_aggregate_opts_t *mongoc_aggregate_opts)
mongoc_write_concern_destroy (mongoc_aggregate_opts->writeConcern);
}
bson_destroy (&mongoc_aggregate_opts->collation);
bson_destroy (&mongoc_aggregate_opts->let);
bson_destroy (&mongoc_aggregate_opts->extra);
}

Expand Down