Storage Engine API
document_validation.h
Go to the documentation of this file.
1 /*
2 * Copyright (C) 2015 MongoDB Inc.
3 *
4 * This program is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU Affero General Public License, version 3,
6 * as published by the Free Software Foundation.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU Affero General Public License for more details.
12 *
13 * You should have received a copy of the GNU Affero General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
15 *
16 * As a special exception, the copyright holders give permission to link the
17 * code of portions of this program with the OpenSSL library under certain
18 * conditions as described in each individual source file and distribute
19 * linked combinations including the program with the OpenSSL library. You
20 * must comply with the GNU Affero General Public License in all respects for
21 * all of the code used other than as permitted herein. If you modify file(s)
22 * with this exception, you may extend this exception to your version of the
23 * file(s), but you are not obligated to do so. If you do not wish to do so,
24 * delete this exception statement from your version. If you delete this
25 * exception statement from all source files in the program, then also delete
26 * it in the license file.
27 */
28 
29 #pragma once
30 
31 #include "mongo/base/disallow_copying.h"
32 #include "mongo/base/string_data.h"
33 #include "mongo/db/operation_context.h"
34 
35 namespace mongo {
41 extern const OperationContext::Decoration<bool> documentValidationDisabled;
42 
44  return "bypassDocumentValidation";
45 }
46 
47 inline bool shouldBypassDocumentValidationForCommand(const BSONObj& cmdObj) {
48  return cmdObj[bypassDocumentValidationCommandOption()].trueValue();
49 }
50 
57 
58 public:
59  DisableDocumentValidation(OperationContext* opCtx)
60  : _opCtx(opCtx), _initialState(documentValidationDisabled(_opCtx)) {
62  }
63 
66  }
67 
68 private:
69  OperationContext* const _opCtx;
70  const bool _initialState;
71 };
72 
77 public:
78  DisableDocumentValidationIfTrue(OperationContext* opCtx, bool shouldDisableValidation) {
79  if (shouldDisableValidation)
80  _documentValidationDisabler.emplace(opCtx);
81  }
82 
83 private:
84  boost::optional<DisableDocumentValidation> _documentValidationDisabler;
85 };
86 }
StringData bypassDocumentValidationCommandOption()
Definition: document_validation.h:43
const OperationContext::Decoration< bool > documentValidationDisabled
If true, Collection should do no validation of writes from this OperationContext. ...
Definition: document_validation.cpp:34
DisableDocumentValidationIfTrue(OperationContext *opCtx, bool shouldDisableValidation)
Definition: document_validation.h:78
OperationContext *const _opCtx
Definition: document_validation.h:69
Copyright (C) 2014 MongoDB Inc.
Definition: bson_collection_catalog_entry.cpp:38
Disables document validation while in scope if the constructor is passed true.
Definition: document_validation.h:76
~DisableDocumentValidation()
Definition: document_validation.h:64
bool shouldBypassDocumentValidationForCommand(const BSONObj &cmdObj)
Definition: document_validation.h:47
MONGO_DISALLOW_COPYING(DisableDocumentValidation)
Disables document validation on a single OperationContext while in scope.
Definition: document_validation.h:55
const bool _initialState
Definition: document_validation.h:70
Collection *const OperationContext *const opCtx
Definition: collection_impl.cpp:80
DisableDocumentValidation(OperationContext *opCtx)
Definition: document_validation.h:59
boost::optional< DisableDocumentValidation > _documentValidationDisabler
Definition: document_validation.h:84