Skip to content

Commit 220ecf8

Browse files
committed
CXX-1059 Minor cleanup of pipeline.cpp/pipeline.hpp
Simplify implementation, clean up documentation, fix naming of a few parameters.
1 parent 6f4f6d1 commit 220ecf8

File tree

2 files changed

+51
-46
lines changed

2 files changed

+51
-46
lines changed

src/mongocxx/pipeline.cpp

Lines changed: 12 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ namespace mongocxx {
2424
MONGOCXX_INLINE_NAMESPACE_BEGIN
2525

2626
using namespace bsoncxx::builder::stream;
27-
using namespace bsoncxx::types;
2827

2928
pipeline::pipeline() : _impl(stdx::make_unique<impl>()) {
3029
}
@@ -33,8 +32,8 @@ pipeline::pipeline(pipeline&&) noexcept = default;
3332
pipeline& pipeline::operator=(pipeline&&) noexcept = default;
3433
pipeline::~pipeline() = default;
3534

36-
pipeline& pipeline::group(bsoncxx::document::view_or_value group) {
37-
_impl->sink() << open_document << "$group" << b_document{std::move(group)} << close_document;
35+
pipeline& pipeline::group(bsoncxx::document::view_or_value group_args) {
36+
_impl->sink() << open_document << "$group" << group_args << close_document;
3837
return *this;
3938
}
4039

@@ -43,13 +42,13 @@ pipeline& pipeline::limit(std::int32_t limit) {
4342
return *this;
4443
}
4544

46-
pipeline& pipeline::lookup(bsoncxx::document::view_or_value lookup) {
47-
_impl->sink() << open_document << "$lookup" << b_document{std::move(lookup)} << close_document;
45+
pipeline& pipeline::lookup(bsoncxx::document::view_or_value lookup_args) {
46+
_impl->sink() << open_document << "$lookup" << lookup_args << close_document;
4847
return *this;
4948
}
5049

51-
pipeline& pipeline::match(bsoncxx::document::view_or_value criteria) {
52-
_impl->sink() << open_document << "$match" << b_document{std::move(criteria)} << close_document;
50+
pipeline& pipeline::match(bsoncxx::document::view_or_value filter) {
51+
_impl->sink() << open_document << "$match" << filter << close_document;
5352
return *this;
5453
}
5554

@@ -59,14 +58,12 @@ pipeline& pipeline::out(std::string collection_name) {
5958
}
6059

6160
pipeline& pipeline::project(bsoncxx::document::view_or_value projection) {
62-
_impl->sink() << open_document << "$project" << b_document{std::move(projection)}
63-
<< close_document;
61+
_impl->sink() << open_document << "$project" << projection << close_document;
6462
return *this;
6563
}
6664

6765
pipeline& pipeline::redact(bsoncxx::document::view_or_value restrictions) {
68-
_impl->sink() << open_document << "$redact" << b_document{std::move(restrictions)}
69-
<< close_document;
66+
_impl->sink() << open_document << "$redact" << restrictions << close_document;
7067
return *this;
7168
}
7269

@@ -76,13 +73,13 @@ pipeline& pipeline::sample(std::int32_t size) {
7673
return *this;
7774
}
7875

79-
pipeline& pipeline::skip(std::int32_t skip) {
80-
_impl->sink() << open_document << "$skip" << skip << close_document;
76+
pipeline& pipeline::skip(std::int32_t docs_to_skip) {
77+
_impl->sink() << open_document << "$skip" << docs_to_skip << close_document;
8178
return *this;
8279
}
8380

84-
pipeline& pipeline::sort(bsoncxx::document::view_or_value sort) {
85-
_impl->sink() << open_document << "$sort" << b_document{std::move(sort)} << close_document;
81+
pipeline& pipeline::sort(bsoncxx::document::view_or_value ordering) {
82+
_impl->sink() << open_document << "$sort" << ordering << close_document;
8683
return *this;
8784
}
8885

src/mongocxx/pipeline.hpp

Lines changed: 39 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -58,25 +58,27 @@ class MONGOCXX_API pipeline {
5858

5959
///
6060
/// Groups documents by some specified expression and outputs to the next stage a
61-
/// document for each distinct grouping. The output documents contain an @c _id field
61+
/// document for each distinct grouping. The output documents contain an `_id` field
6262
/// which contains the the distinct key for that group. The output documents can also
6363
/// contain computed fields that hold the values of some accumulator expression grouped
64-
/// by the group's @c _id field.
64+
/// by the group's `_id` field.
6565
///
6666
/// @note group does not order output documents.
6767
///
68-
/// @see http://docs.mongodb.org/manual/reference/operator/aggregation/group/#pipe._S_group
68+
/// @see http://docs.mongodb.org/manual/reference/operator/aggregation/group/
6969
///
70-
/// @param group the group expression, as a document.
70+
/// @param group_args
71+
/// The specification for the group operation. The required field `_id` must be included.
7172
///
72-
pipeline& group(bsoncxx::document::view_or_value group);
73+
pipeline& group(bsoncxx::document::view_or_value group_args);
7374

7475
///
7576
/// Limits the number of documents passed to the next stage in the pipeline.
7677
///
77-
/// @see http://docs.mongodb.org/manual/reference/operator/aggregation/limit/#pipe._S_limit
78+
/// @see http://docs.mongodb.org/manual/reference/operator/aggregation/limit/
7879
///
79-
/// @param limit the number of documents to which output should be limited.
80+
/// @param limit
81+
/// The number of documents to which output should be limited.
8082
///
8183
pipeline& limit(std::int32_t limit);
8284

@@ -86,21 +88,20 @@ class MONGOCXX_API pipeline {
8688
///
8789
/// @see https://docs.mongodb.org/manual/reference/operator/aggregation/lookup/
8890
///
89-
/// @param lookup the lookup expression, as a document with the following fields:
90-
/// from: <collection to join>
91-
/// localField: <field from the input documents>
92-
/// foreignField: <field from the documents of the "from" collection>
93-
/// as: <output array field>
91+
/// @param lookup_args
92+
/// The specification for the lookup operation. The required fields `from`, `localField`,
93+
/// `foreignField`, and `as` must be included.
9494
///
95-
pipeline& lookup(bsoncxx::document::view_or_value lookup);
95+
pipeline& lookup(bsoncxx::document::view_or_value lookup_args);
9696

9797
///
9898
/// Filters the documents. Only the documents that match the condition(s) specified by the
99-
/// @c filter will continue to the next pipeline stage.
99+
/// `filter` will continue to the next pipeline stage.
100100
///
101-
/// @see http://docs.mongodb.org/manual/reference/operator/aggregation/match/#pipe._S_match
101+
/// @see http://docs.mongodb.org/manual/reference/operator/aggregation/match/
102102
///
103-
/// @param filter the filter.
103+
/// @param filter
104+
/// The filter.
104105
///
105106
pipeline& match(bsoncxx::document::view_or_value filter);
106107

@@ -109,57 +110,63 @@ class MONGOCXX_API pipeline {
109110
/// collection. This stage must be the last stage in the pipeline. The out operator lets the
110111
/// aggregation framework return result sets of any size.
111112
///
112-
/// @see http://docs.mongodb.org/manual/reference/operator/aggregation/out/#pipe._S_out
113+
/// @see http://docs.mongodb.org/manual/reference/operator/aggregation/out/
113114
///
114-
/// @param collection_name the name of the collection where the output documents should go
115+
/// @param collection_name
116+
/// The name of the collection where the output documents should go.
115117
///
116118
pipeline& out(std::string collection_name);
117119

118120
///
119121
/// Projects a subset of the fields in the documents to the next stage of the pipeline.
120122
///
121-
/// @see http://docs.mongodb.org/manual/reference/operator/aggregation/project/#pipe._S_project
123+
/// @see http://docs.mongodb.org/manual/reference/operator/aggregation/project/
122124
///
123-
/// @param projection projection specification.
125+
/// @param projection
126+
/// The projection specification.
124127
///
125128
pipeline& project(bsoncxx::document::view_or_value projection);
126129

127130
///
128131
/// Restricts the contents of the documents based on information stored in the documents
129132
/// themselves.
130133
///
131-
/// @see http://docs.mongodb.org/manual/reference/operator/aggregation/redact/#pipe._S_redact
134+
/// @see http://docs.mongodb.org/manual/reference/operator/aggregation/redact/
132135
///
133-
/// @param restrictions the document restrictions.
136+
/// @param restrictions
137+
/// The document restrictions.
134138
///
135139
pipeline& redact(bsoncxx::document::view_or_value restrictions);
136140

137141
///
138142
/// Randomly selects the specified number of documents that pass into the stage and passes the
139143
/// remaining documents to the next stage in the pipeline.
140144
///
141-
/// @see http://docs.mongodb.org/manual/reference/operator/aggregation/sample/#pipe._S_sample
145+
/// @see http://docs.mongodb.org/manual/reference/operator/aggregation/sample/
142146
///
143-
/// @param size the number of input documents to select.
147+
/// @param size
148+
/// The number of input documents to select.
144149
///
145150
pipeline& sample(std::int32_t size);
146151

147152
///
148153
/// Skips over the specified number of documents that pass into the stage and passes the
149154
/// remaining documents to the next stage in the pipeline.
150155
///
151-
/// @see http://docs.mongodb.org/manual/reference/operator/aggregation/skip/#pipe._S_skip
156+
/// @see http://docs.mongodb.org/manual/reference/operator/aggregation/skip/
152157
///
153-
/// @param skip the number of input documents to skip.
158+
/// @param docs_to_skip
159+
/// The number of input documents to skip.
154160
///
155-
pipeline& skip(std::int32_t skip);
161+
pipeline& skip(std::int32_t docs_to_skip);
156162

157163
///
158164
/// Sorts all input documents and returns them to the pipeline in sorted order.
159165
///
160-
/// @see http://docs.mongodb.org/manual/reference/operator/aggregation/sort/#pipe._S_sort
166+
/// @see http://docs.mongodb.org/manual/reference/operator/aggregation/sort/
161167
///
162-
/// @param ordering document specifying the ordering by which the documents are sorted.
168+
/// @param ordering
169+
/// Document specifying the ordering by which the documents are sorted.
163170
///
164171
pipeline& sort(bsoncxx::document::view_or_value ordering);
165172

@@ -168,9 +175,10 @@ class MONGOCXX_API pipeline {
168175
/// Each output document is an input document with the value of its array field replaced by
169176
/// an element from the unwound array.
170177
///
171-
/// @see http://docs.mongodb.org/manual/reference/operator/aggregation/unwind/#pipe._S_unwind
178+
/// @see http://docs.mongodb.org/manual/reference/operator/aggregation/unwind/
172179
///
173-
/// @param field_name the name of the field to unwind.
180+
/// @param field_name
181+
/// The name of the field to unwind.
174182
///
175183
pipeline& unwind(std::string field_name);
176184

0 commit comments

Comments
 (0)