Loading...
Searching...
No Matches
pipeline.hpp
Go to the documentation of this file.
// Copyright 2009-present MongoDB, Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#pragma once
#include <mongocxx/pipeline-fwd.hpp> // IWYU pragma: export
//
#include <mongocxx/v1/pipeline.hpp> // IWYU pragma: export
#include <cstdint>
#include <memory> // IWYU pragma: keep: backward compatibility, to be removed.
#include <string>
#include <utility>
#include <mongocxx/client-fwd.hpp> // IWYU pragma: keep: backward compatibility, to be removed.
#include <mongocxx/collection-fwd.hpp> // IWYU pragma: keep: backward compatibility, to be removed.
#include <mongocxx/database-fwd.hpp> // IWYU pragma: keep: backward compatibility, to be removed.
#include <bsoncxx/array/view.hpp>
#include <bsoncxx/array/view_or_value.hpp>
#include <bsoncxx/document/view.hpp>
#include <bsoncxx/document/view_or_value.hpp>
#include <mongocxx/config/prelude.hpp>
namespace mongocxx {
namespace v_noabi {
class pipeline {
private:
v1::pipeline _pipeline;
public:
pipeline() = default;
pipeline(pipeline&& other) noexcept = default;
pipeline& operator=(pipeline&& other) noexcept = default;
~pipeline() = default;
pipeline(pipeline const& other) = delete;
pipeline& operator=(pipeline const& other) = delete;
/* explicit(false) */ pipeline(v1::pipeline pipeline) : _pipeline{std::move(pipeline)} {}
explicit operator v1::pipeline() && {
return std::move(_pipeline);
}
explicit operator v1::pipeline() const& {
return _pipeline;
}
pipeline& add_fields(bsoncxx::v_noabi::document::view_or_value fields_to_add) {
_pipeline.add_fields(bsoncxx::v_noabi::to_v1(fields_to_add.view()));
return *this;
}
pipeline& bucket(bsoncxx::v_noabi::document::view_or_value bucket_args) {
_pipeline.bucket(bsoncxx::v_noabi::to_v1(bucket_args.view()));
return *this;
}
pipeline& bucket_auto(bsoncxx::v_noabi::document::view_or_value bucket_auto_args) {
_pipeline.bucket_auto(bsoncxx::v_noabi::to_v1(bucket_auto_args.view()));
return *this;
}
pipeline& coll_stats(
bsoncxx::v_noabi::document::view_or_value coll_stats_args = bsoncxx::v_noabi::document::view{}) {
_pipeline.coll_stats(bsoncxx::v_noabi::to_v1(coll_stats_args.view()));
return *this;
}
pipeline& count(std::string field) {
_pipeline.count(field);
return *this;
}
pipeline& current_op(bsoncxx::v_noabi::document::view_or_value current_op_args) {
_pipeline.current_op(bsoncxx::v_noabi::to_v1(current_op_args.view()));
return *this;
}
pipeline& facet(bsoncxx::v_noabi::document::view_or_value facet_args) {
_pipeline.facet(bsoncxx::v_noabi::to_v1(facet_args.view()));
return *this;
}
pipeline& append_stage(bsoncxx::v_noabi::document::view_or_value stage) {
_pipeline.append_stage(bsoncxx::v_noabi::to_v1(stage.view()));
return *this;
}
pipeline& append_stages(bsoncxx::v_noabi::array::view_or_value stages) {
_pipeline.append_stages(bsoncxx::v_noabi::to_v1(stages.view()));
return *this;
}
pipeline& geo_near(bsoncxx::v_noabi::document::view_or_value geo_near_args) {
_pipeline.geo_near(bsoncxx::v_noabi::to_v1(geo_near_args.view()));
return *this;
}
pipeline& graph_lookup(bsoncxx::v_noabi::document::view_or_value graph_lookup_args) {
_pipeline.graph_lookup(bsoncxx::v_noabi::to_v1(graph_lookup_args.view()));
return *this;
}
pipeline& group(bsoncxx::v_noabi::document::view_or_value group_args) {
_pipeline.group(bsoncxx::v_noabi::to_v1(group_args.view()));
return *this;
}
pipeline& index_stats() {
_pipeline.index_stats();
return *this;
}
pipeline& limit(std::int32_t limit) {
_pipeline.limit(limit);
return *this;
}
pipeline& list_local_sessions(bsoncxx::v_noabi::document::view_or_value list_local_sessions_args) {
_pipeline.list_local_sessions(bsoncxx::v_noabi::to_v1(list_local_sessions_args.view()));
return *this;
}
pipeline& list_sessions(bsoncxx::v_noabi::document::view_or_value list_sessions_args) {
_pipeline.list_sessions(bsoncxx::v_noabi::to_v1(list_sessions_args.view()));
return *this;
}
pipeline& lookup(bsoncxx::v_noabi::document::view_or_value lookup_args) {
_pipeline.lookup(bsoncxx::v_noabi::to_v1(lookup_args.view()));
return *this;
}
pipeline& match(bsoncxx::v_noabi::document::view_or_value filter) {
_pipeline.match(bsoncxx::v_noabi::to_v1(filter.view()));
return *this;
}
pipeline& merge(bsoncxx::v_noabi::document::view_or_value merge_args) {
_pipeline.merge(bsoncxx::v_noabi::to_v1(merge_args.view()));
return *this;
}
pipeline& out(std::string collection_name) {
_pipeline.out(collection_name);
return *this;
}
pipeline& project(bsoncxx::v_noabi::document::view_or_value projection) {
_pipeline.project(bsoncxx::v_noabi::to_v1(projection.view()));
return *this;
}
pipeline& redact(bsoncxx::v_noabi::document::view_or_value restrictions) {
_pipeline.redact(bsoncxx::v_noabi::to_v1(restrictions.view()));
return *this;
}
pipeline& replace_root(bsoncxx::v_noabi::document::view_or_value replace_root_args) {
_pipeline.replace_root(bsoncxx::v_noabi::to_v1(replace_root_args.view()));
return *this;
}
pipeline& sample(std::int32_t size) {
_pipeline.sample(size);
return *this;
}
pipeline& skip(std::int32_t docs_to_skip) {
_pipeline.skip(docs_to_skip);
return *this;
}
pipeline& sort(bsoncxx::v_noabi::document::view_or_value ordering) {
_pipeline.sort(bsoncxx::v_noabi::to_v1(ordering.view()));
return *this;
}
pipeline& sort_by_count(bsoncxx::v_noabi::document::view_or_value field_expression) {
_pipeline.sort_by_count(bsoncxx::v_noabi::to_v1(field_expression.view()));
return *this;
}
pipeline& sort_by_count(std::string field_expression) {
_pipeline.sort_by_count(field_expression);
return *this;
}
pipeline& unwind(bsoncxx::v_noabi::document::view_or_value unwind_args) {
_pipeline.unwind(bsoncxx::v_noabi::to_v1(unwind_args.view()));
return *this;
}
pipeline& unwind(std::string field_name) {
_pipeline.unwind(field_name);
return *this;
}
bsoncxx::v_noabi::array::view view_array() const {
return _pipeline.view_array();
}
class internal;
};
inline v_noabi::pipeline from_v1(v1::pipeline v) {
return {std::move(v)};
}
inline v1::pipeline to_v1(v_noabi::pipeline v) {
return v1::pipeline{std::move(v)};
}
} // namespace v_noabi
} // namespace mongocxx
#include <mongocxx/config/postlude.hpp>
view_or_value.hpp
Provides bsoncxx::v_noabi::array::view_or_value.
bsoncxx::v_noabi::array::view
A read-only, non-owning view of a BSON document.
Definition view.hpp:41
bsoncxx::v_noabi::document::view
A read-only, non-owning view of a BSON document.
Definition view.hpp:40
bsoncxx::v_noabi::view_or_value::view
View const & view() const
Get a View for the type.
Definition view_or_value.hpp:135
mongocxx::pipeline::pipeline
pipeline()=default
Creates a new aggregation pipeline.
mongocxx::v1::pipeline
A MongoDB aggregation pipeline.
Definition pipeline.hpp:41
mongocxx::v1::pipeline::coll_stats
pipeline & coll_stats(bsoncxx::v1::document::view v)
Append the "$collStats" stage.
mongocxx::v_noabi::pipeline
A MongoDB aggregation pipeline.
Definition pipeline.hpp:45
mongocxx::v_noabi::pipeline::pipeline
pipeline()=default
Creates a new aggregation pipeline.
mongocxx::v_noabi::pipeline::geo_near
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
mongocxx::v_noabi::pipeline::graph_lookup
pipeline & graph_lookup(bsoncxx::v_noabi::document::view_or_value graph_lookup_args)
Performs a recursive search on a collection.
Definition pipeline.hpp:313
mongocxx::v_noabi::pipeline::bucket
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
mongocxx::v_noabi::pipeline::skip
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
mongocxx::v_noabi::pipeline::index_stats
pipeline & index_stats()
Returns statistics regarding the use of each index for the collection.
Definition pipeline.hpp:352
mongocxx::v_noabi::pipeline::unwind
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
mongocxx::v_noabi::pipeline::lookup
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
mongocxx::v_noabi::pipeline::count
pipeline & count(std::string field)
Returns a document containing a count of the number of documents input to the stage.
Definition pipeline.hpp:194
mongocxx::v_noabi::pipeline::group
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
mongocxx::v_noabi::pipeline::replace_root
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
mongocxx::v_noabi::pipeline::append_stage
pipeline & append_stage(bsoncxx::v_noabi::document::view_or_value stage)
Appends a stage to this pipeline object.
Definition pipeline.hpp:255
mongocxx::v_noabi::pipeline::pipeline
pipeline(pipeline &&other) noexcept=default
Move constructs a pipeline.
mongocxx::v_noabi::pipeline::add_fields
pipeline & add_fields(bsoncxx::v_noabi::document::view_or_value fields_to_add)
Adds new fields to documents.
Definition pipeline.hpp:115
mongocxx::v_noabi::pipeline::list_local_sessions
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
mongocxx::v_noabi::pipeline::~pipeline
~pipeline()=default
Destroys a pipeline.
mongocxx::v_noabi::pipeline::view_array
bsoncxx::v_noabi::array::view view_array() const
Definition pipeline.hpp:700
mongocxx::v_noabi::pipeline::current_op
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
mongocxx::v_noabi::pipeline::coll_stats
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
mongocxx::v_noabi::pipeline::unwind
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
mongocxx::v_noabi::pipeline::merge
pipeline & merge(bsoncxx::v_noabi::document::view_or_value merge_args)
Outputs the aggregation results to a collection.
Definition pipeline.hpp:465
mongocxx::v_noabi::pipeline::sort
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
mongocxx::v_noabi::pipeline::list_sessions
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
mongocxx::v_noabi::pipeline::sort_by_count
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
mongocxx::v_noabi::pipeline::redact
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
mongocxx::v_noabi::pipeline::project
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
mongocxx::v_noabi::pipeline::operator=
pipeline & operator=(pipeline &&other) noexcept=default
Move assigns a pipeline.
mongocxx::v_noabi::pipeline::out
pipeline & out(std::string collection_name)
Takes documents returned by the aggregation pipeline and writes them to a specified collection....
Definition pipeline.hpp:485
mongocxx::v_noabi::pipeline::pipeline
pipeline(v1::pipeline pipeline)
Construct with the mongocxx::v1 equivalent.
Definition pipeline.hpp:79
mongocxx::v_noabi::pipeline::facet
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
mongocxx::v_noabi::pipeline::match
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
mongocxx::v_noabi::pipeline::append_stages
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
mongocxx::v_noabi::pipeline::sort_by_count
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
mongocxx::v_noabi::pipeline::sample
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
mongocxx::v_noabi::pipeline::bucket_auto
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
mongocxx::v_noabi::pipeline::limit
pipeline & limit(std::int32_t limit)
Limits the number of documents passed to the next stage in the pipeline.
Definition pipeline.hpp:370
view_or_value.hpp
Provides bsoncxx::v_noabi::document::view_or_value.
postlude.hpp
The mongocxx v_noabi macro guard postlude header.
prelude.hpp
The mongocxx v_noabi macro guard prelude header.
bsoncxx::v_noabi::array::view_or_value
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
bsoncxx::v_noabi::document::view_or_value
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
bsoncxx::v_noabi::to_v1
v1::element::view to_v1(v_noabi::array::element const &v)
Convert to the bsoncxx::v1 equivalent of v.
Definition element.hpp:132
mongocxx::v_noabi
Declares entities whose ABI stability is NOT guaranteed.
mongocxx::v_noabi::to_v1
v1::bulk_write to_v1(v_noabi::bulk_write v)
Convert to the mongocxx::v1 equivalent of v.
Definition bulk_write.hpp:162
mongocxx::v_noabi::from_v1
v_noabi::bulk_write from_v1(v1::bulk_write v)
Convert to the mongocxx::v_noabi equivalent of v.
Definition bulk_write.hpp:155
mongocxx
The top-level namespace within which all mongocxx library entities are declared.
pipeline.hpp
Provides mongocxx::v1::pipeline.
view.hpp
Provides bsoncxx::v_noabi::array::view.
view.hpp
Provides bsoncxx::v_noabi::document::view.
client-fwd.hpp
Declares mongocxx::v_noabi::client.
collection-fwd.hpp
Declares mongocxx::v_noabi::collection.
database-fwd.hpp
Declares mongocxx::v_noabi::database.
pipeline-fwd.hpp
Declares mongocxx::v_noabi::pipeline.