MongoDB C++ Driver 4.2.0
Loading...
Searching...
No Matches
pipeline.hpp
Go to the documentation of this file.
1// Copyright 2009-present MongoDB, Inc.
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7// http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
15#pragma once
16
17#include <mongocxx/pipeline-fwd.hpp> // IWYU pragma: export
18
19//
20
21#include <mongocxx/v1/pipeline.hpp> // IWYU pragma: export
22
23#include <cstdint>
24#include <memory> // IWYU pragma: keep: backward compatibility, to be removed.
25#include <string>
26#include <utility>
27
28#include <mongocxx/client-fwd.hpp> // IWYU pragma: keep: backward compatibility, to be removed.
29#include <mongocxx/collection-fwd.hpp> // IWYU pragma: keep: backward compatibility, to be removed.
30#include <mongocxx/database-fwd.hpp> // IWYU pragma: keep: backward compatibility, to be removed.
31
36
38
39namespace mongocxx {
40namespace v_noabi {
41
45class pipeline {
46 private:
47 v1::pipeline _pipeline;
48
49 public:
56 pipeline() = default;
57
61 pipeline(pipeline&& other) noexcept = default;
62
66 pipeline& operator=(pipeline&& other) noexcept = default;
67
71 ~pipeline() = default;
72
73 pipeline(pipeline const& other) = delete;
74 pipeline& operator=(pipeline const& other) = delete;
75
79 /* explicit(false) */ pipeline(v1::pipeline pipeline) : _pipeline{std::move(pipeline)} {}
80
89 explicit operator v1::pipeline() && {
90 return std::move(_pipeline);
91 }
92
96 explicit operator v1::pipeline() const& {
97 return _pipeline;
98 }
99
116 _pipeline.add_fields(bsoncxx::v_noabi::to_v1(fields_to_add.view()));
117 return *this;
118 }
119
136 _pipeline.bucket(bsoncxx::v_noabi::to_v1(bucket_args.view()));
137 return *this;
138 }
139
157 _pipeline.bucket_auto(bsoncxx::v_noabi::to_v1(bucket_auto_args.view()));
158 return *this;
159 }
160
177 _pipeline.coll_stats(bsoncxx::v_noabi::to_v1(coll_stats_args.view()));
178 return *this;
179 }
180
194 pipeline& count(std::string field) {
195 _pipeline.count(field);
196 return *this;
197 }
198
216 _pipeline.current_op(bsoncxx::v_noabi::to_v1(current_op_args.view()));
217 return *this;
218 }
219
236 _pipeline.facet(bsoncxx::v_noabi::to_v1(facet_args.view()));
237 return *this;
238 }
239
259
279
295 _pipeline.geo_near(bsoncxx::v_noabi::to_v1(geo_near_args.view()));
296 return *this;
297 }
298
314 _pipeline.graph_lookup(bsoncxx::v_noabi::to_v1(graph_lookup_args.view()));
315 return *this;
316 }
317
338 _pipeline.group(bsoncxx::v_noabi::to_v1(group_args.view()));
339 return *this;
340 }
341
353 _pipeline.index_stats();
354 return *this;
355 }
356
370 pipeline& limit(std::int32_t limit) {
371 _pipeline.limit(limit);
372 return *this;
373 }
374
390 _pipeline.list_local_sessions(bsoncxx::v_noabi::to_v1(list_local_sessions_args.view()));
391 return *this;
392 }
393
408 _pipeline.list_sessions(bsoncxx::v_noabi::to_v1(list_sessions_args.view()));
409 return *this;
410 }
411
428 _pipeline.lookup(bsoncxx::v_noabi::to_v1(lookup_args.view()));
429 return *this;
430 }
431
447 _pipeline.match(bsoncxx::v_noabi::to_v1(filter.view()));
448 return *this;
449 }
450
466 _pipeline.merge(bsoncxx::v_noabi::to_v1(merge_args.view()));
467 return *this;
468 }
469
485 pipeline& out(std::string collection_name) {
486 _pipeline.out(collection_name);
487 return *this;
488 }
489
504 _pipeline.project(bsoncxx::v_noabi::to_v1(projection.view()));
505 return *this;
506 }
507
523 _pipeline.redact(bsoncxx::v_noabi::to_v1(restrictions.view()));
524 return *this;
525 }
526
542 _pipeline.replace_root(bsoncxx::v_noabi::to_v1(replace_root_args.view()));
543 return *this;
544 }
545
560 pipeline& sample(std::int32_t size) {
561 _pipeline.sample(size);
562 return *this;
563 }
564
579 pipeline& skip(std::int32_t docs_to_skip) {
580 _pipeline.skip(docs_to_skip);
581 return *this;
582 }
583
598 _pipeline.sort(bsoncxx::v_noabi::to_v1(ordering.view()));
599 return *this;
600 }
601
621 _pipeline.sort_by_count(bsoncxx::v_noabi::to_v1(field_expression.view()));
622 return *this;
623 }
624
644 pipeline& sort_by_count(std::string field_expression) {
645 _pipeline.sort_by_count(field_expression);
646 return *this;
647 }
648
669 _pipeline.unwind(bsoncxx::v_noabi::to_v1(unwind_args.view()));
670 return *this;
671 }
672
692 pipeline& unwind(std::string field_name) {
693 _pipeline.unwind(field_name);
694 return *this;
695 }
696
701 return _pipeline.view_array();
702 }
703
704 class internal;
705};
706
707} // namespace v_noabi
708} // namespace mongocxx
709
711
Provides bsoncxx::v_noabi::array::view_or_value.
A read-only, non-owning view of a BSON document.
Definition view.hpp:41
A read-only, non-owning view of a BSON document.
Definition view.hpp:40
View const & view() const
Get a View for the type.
Definition view_or_value.hpp:135
pipeline()=default
Creates a new aggregation pipeline.
A MongoDB aggregation pipeline.
Definition pipeline.hpp:43
pipeline & coll_stats(bsoncxx::v1::document::view v)
Append the "$collStats" stage.
pipeline()=default
Creates a new aggregation pipeline.
pipeline & geo_near(bsoncxx::v_noabi::document::view_or_value geo_near_args)
Outputs documents in order of nearest to farthest from a specified point.
Definition pipeline.hpp:294
pipeline & graph_lookup(bsoncxx::v_noabi::document::view_or_value graph_lookup_args)
Performs a recursive search on a collection.
Definition pipeline.hpp:313
pipeline & bucket(bsoncxx::v_noabi::document::view_or_value bucket_args)
Categorizes documents into groups, called buckets, based on a specified expression and bucket boundar...
Definition pipeline.hpp:135
pipeline & skip(std::int32_t docs_to_skip)
Skips over the specified number of documents that pass into the stage and passes the remaining docume...
Definition pipeline.hpp:579
pipeline & index_stats()
Returns statistics regarding the use of each index for the collection.
Definition pipeline.hpp:352
pipeline & unwind(std::string field_name)
Deconstructs an array field from the input documents to output a document for each element....
Definition pipeline.hpp:692
pipeline & lookup(bsoncxx::v_noabi::document::view_or_value lookup_args)
Performs a left outer join to an unsharded collection in the same database to filter in documents fro...
Definition pipeline.hpp:427
pipeline & count(std::string field)
Returns a document containing a count of the number of documents input to the stage.
Definition pipeline.hpp:194
pipeline & group(bsoncxx::v_noabi::document::view_or_value group_args)
Groups documents by some specified expression and outputs to the next stage a document for each disti...
Definition pipeline.hpp:337
pipeline & replace_root(bsoncxx::v_noabi::document::view_or_value replace_root_args)
Promotes a specified document to the top level and replaces all other fields.
Definition pipeline.hpp:541
pipeline & append_stage(bsoncxx::v_noabi::document::view_or_value stage)
Appends a stage to this pipeline object.
Definition pipeline.hpp:255
pipeline(pipeline &&other) noexcept=default
Move constructs a pipeline.
pipeline & add_fields(bsoncxx::v_noabi::document::view_or_value fields_to_add)
Adds new fields to documents.
Definition pipeline.hpp:115
pipeline & list_local_sessions(bsoncxx::v_noabi::document::view_or_value list_local_sessions_args)
Lists the sessions cached in memory by the mongod or mongos instance.
Definition pipeline.hpp:389
~pipeline()=default
Destroys a pipeline.
bsoncxx::v_noabi::array::view view_array() const
Definition pipeline.hpp:700
pipeline & current_op(bsoncxx::v_noabi::document::view_or_value current_op_args)
Returns a stream of documents containing information on active and/or dormant operations as well as i...
Definition pipeline.hpp:215
pipeline & coll_stats(bsoncxx::v_noabi::document::view_or_value coll_stats_args=bsoncxx::v_noabi::document::view{})
Returns statistics regarding a collection or view.
Definition pipeline.hpp:175
pipeline & unwind(bsoncxx::v_noabi::document::view_or_value unwind_args)
Deconstructs an array field from the input documents to output a document for each element....
Definition pipeline.hpp:668
pipeline & merge(bsoncxx::v_noabi::document::view_or_value merge_args)
Outputs the aggregation results to a collection.
Definition pipeline.hpp:465
pipeline & sort(bsoncxx::v_noabi::document::view_or_value ordering)
Sorts all input documents and returns them to the pipeline in sorted order.
Definition pipeline.hpp:597
pipeline & list_sessions(bsoncxx::v_noabi::document::view_or_value list_sessions_args)
Lists all sessions stored in the system.sessions collection in the config database....
Definition pipeline.hpp:407
pipeline & sort_by_count(std::string field_expression)
Groups incoming documents based on the value of a specified expression, then computes the count of do...
Definition pipeline.hpp:644
pipeline & redact(bsoncxx::v_noabi::document::view_or_value restrictions)
Restricts the contents of the documents based on information stored in the documents themselves.
Definition pipeline.hpp:522
pipeline & project(bsoncxx::v_noabi::document::view_or_value projection)
Projects a subset of the fields in the documents to the next stage of the pipeline.
Definition pipeline.hpp:503
pipeline & operator=(pipeline &&other) noexcept=default
Move assigns a pipeline.
pipeline & out(std::string collection_name)
Takes documents returned by the aggregation pipeline and writes them to a specified collection....
Definition pipeline.hpp:485
pipeline(v1::pipeline pipeline)
Construct with the mongocxx::v1 equivalent.
Definition pipeline.hpp:79
pipeline & facet(bsoncxx::v_noabi::document::view_or_value facet_args)
Processes multiple aggregation pipelines within a single stage on the same set of input documents.
Definition pipeline.hpp:235
pipeline & match(bsoncxx::v_noabi::document::view_or_value filter)
Filters the documents. Only the documents that match the condition(s) specified by the filter will co...
Definition pipeline.hpp:446
pipeline & append_stages(bsoncxx::v_noabi::array::view_or_value stages)
Appends stages to this pipeline object from the given bson array.
Definition pipeline.hpp:275
pipeline & sort_by_count(bsoncxx::v_noabi::document::view_or_value field_expression)
Groups incoming documents based on the value of a specified expression, then computes the count of do...
Definition pipeline.hpp:620
pipeline & sample(std::int32_t size)
Randomly selects the specified number of documents that pass into the stage and passes the remaining ...
Definition pipeline.hpp:560
pipeline & bucket_auto(bsoncxx::v_noabi::document::view_or_value bucket_auto_args)
Categorizes documents into a specific number of groups, called buckets, based on a specified expressi...
Definition pipeline.hpp:156
pipeline & limit(std::int32_t limit)
Limits the number of documents passed to the next stage in the pipeline.
Definition pipeline.hpp:370
Provides bsoncxx::v_noabi::document::view_or_value.
The mongocxx v_noabi macro guard postlude header.
The mongocxx v_noabi macro guard prelude header.
v_noabi::view_or_value< view, value > view_or_value
Equivalent to v_noabi::view_or_value<v_noabi::array::view, v_noabi::array::value>.
Definition view_or_value.hpp:31
v_noabi::view_or_value< v_noabi::document::view, v_noabi::document::value > view_or_value
Equivalent to v_noabi::view_or_value<v_noabi::document::view, v_noabi::document::value>.
Definition view_or_value.hpp:30
v1::element::view to_v1(v_noabi::array::element const &v)
Convert to the bsoncxx::v1 equivalent of v.
Definition element.hpp:132
Declares entities whose ABI stability is NOT guaranteed.
The top-level namespace within which all mongocxx library entities are declared.
Provides mongocxx::v1::pipeline.
Provides bsoncxx::v_noabi::array::view.
Provides bsoncxx::v_noabi::document::view.
Declares mongocxx::v_noabi::client.
Declares mongocxx::v_noabi::collection.
Declares mongocxx::v_noabi::database.
Declares mongocxx::v_noabi::pipeline.