1 2 /** 3 * Copyright (C) 2018-present MongoDB, Inc. 4 * 5 * This program is free software: you can redistribute it and/or modify 6 * it under the terms of the Server Side Public License, version 1, 7 * as published by MongoDB, Inc. 8 * 9 * This program is distributed in the hope that it will be useful, 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 * Server Side Public License for more details. 13 * 14 * You should have received a copy of the Server Side Public License 15 * along with this program. If not, see 16 * <http://www.mongodb.com/licensing/server-side-public-license>. 17 * 18 * As a special exception, the copyright holders give permission to link the 19 * code of portions of this program with the OpenSSL library under certain 20 * conditions as described in each individual source file and distribute 21 * linked combinations including the program with the OpenSSL library. You 22 * must comply with the Server Side Public License in all respects for 23 * all of the code used other than as permitted herein. If you modify file(s) 24 * with this exception, you may extend this exception to your version of the 25 * file(s), but you are not obligated to do so. If you do not wish to do so, 26 * delete this exception statement from your version. If you delete this 27 * exception statement from all source files in the program, then also delete 28 * it in the license file. 29 */ 30 31 #pragma once 32 33 #include <vector> 34 35 #include "mongo/base/status_with.h" 36 #include "mongo/bson/bsonobj.h" 37 #include "mongo/db/namespace_string.h" 38 #include "mongo/db/pipeline/aggregation_request.h" 39 40 namespace mongo { 41 42 /** 43 * Represents a resolved definition, composed of a base collection namespace and a pipeline 44 * built from one or more views. 45 */ 46 class ResolvedView { 47 public: ResolvedView(const NamespaceString & collectionNs,std::vector<BSONObj> pipeline,BSONObj defaultCollation)48 ResolvedView(const NamespaceString& collectionNs, 49 std::vector<BSONObj> pipeline, 50 BSONObj defaultCollation) 51 : _namespace(collectionNs), 52 _pipeline(std::move(pipeline)), 53 _defaultCollation(std::move(defaultCollation)) {} 54 55 /** 56 * Returns whether 'commandResponseObj' contains a CommandOnShardedViewNotSupportedOnMongod 57 * error and resolved view definition. 58 */ 59 static bool isResolvedViewErrorResponse(BSONObj commandResponseObj); 60 61 static ResolvedView fromBSON(BSONObj commandResponseObj); 62 63 BSONObj toBSON() const; 64 65 /** 66 * Convert an aggregation command on a view to the equivalent command against the view's 67 * underlying collection. 68 */ 69 AggregationRequest asExpandedViewAggregation(const AggregationRequest& aggRequest) const; 70 getNamespace()71 const NamespaceString& getNamespace() const { 72 return _namespace; 73 } 74 getPipeline()75 const std::vector<BSONObj>& getPipeline() const { 76 return _pipeline; 77 } 78 getDefaultCollation()79 const BSONObj& getDefaultCollation() const { 80 return _defaultCollation; 81 } 82 83 private: 84 NamespaceString _namespace; 85 std::vector<BSONObj> _pipeline; 86 87 // The default collation associated with this view. An empty object means that the default is 88 // the simple collation. 89 // 90 // Currently all operations which run over a view must use the default collation. This means 91 // that operations on the view which do not specify a collation inherit the default. Operations 92 // on the view which specify any other collation fail with a user error. 93 BSONObj _defaultCollation; 94 }; 95 96 } // namespace mongo 97