MongoDB C++ Driver legacy-1.0.0
Loading...
Searching...
No Matches
write_concern.h
1/* Copyright 2014 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
16#pragma once
17
18#include <bitset>
19#include <string>
20
21#include "mongo/client/export_macros.h"
22#include "mongo/db/jsobj.h"
23
24namespace mongo {
25
35 class MONGO_CLIENT_API WriteConcern {
36 public:
39
45 static const char kMajority[];
46
47 //
48 // Standard write concern levels as defined in the MongoDB manual:
49 // http://docs.mongodb.org/manual/core/write-concern/
50 //
51
54
57
59 static const WriteConcern journaled;
60
63
65 static const WriteConcern majority;
66
75 int32_t nodes() const;
76
84 const std::string& mode() const;
85
91 bool journal() const;
92
98 bool fsync() const;
99
105 int32_t timeout() const;
106
109
111 WriteConcern& mode(const StringData& w);
112
115
117 WriteConcern& fsync(bool fsync);
118
120 WriteConcern& timeout(int timeout);
121
124
126 bool hasMode() const;
127
129 BSONObj obj() const;
130
131 private:
132 // Enabled option book keeping
133 static const size_t kNumOptions = 5;
134 enum Options { kW, kWStr, kJ, kFsync, kTimeout };
135 std::bitset<kNumOptions> _enabled;
136
137 // Actual option values
138 int32_t _w;
139 std::string _w_str;
140 bool _j;
141 bool _fsync;
142 int32_t _timeout;
143 };
144
145} // namespace mongo
C++ representation of a "BSON" object – that is, an extended JSON-style object in a binary representa...
Definition bsonobj.h:78
Class to encapsulate client side "Write Concern" concept.
Definition write_concern.h:35
static const WriteConcern acknowledged
A single node acknowledges the write, equivalent to default constructor.
Definition write_concern.h:56
int32_t nodes() const
Returns an integer representing the number of nodes required for write to be considered successful.
const std::string & mode() const
Returns a string representing the write concern mode.
bool journal() const
If write will only be considered successful when committed to journal.
BSONObj obj() const
Turn write concern into an object for inclusion in GetLastError or write command.
WriteConcern()
Default write concern: equivalent to acknowledged.
static const WriteConcern replicated
Two nodes have acknowledged receipt of the write operation.
Definition write_concern.h:62
int32_t timeout() const
Length of time to block waiting for nodes, journal, or fsync.
WriteConcern & timeout(int timeout)
Sets timeout to wait for write to be successful.
bool hasMode() const
Whether the write concern currently reflects a mode.
bool fsync() const
If write will only be considered successful when committed to data files.
static const WriteConcern unacknowledged
Fire and forget.
Definition write_concern.h:53
WriteConcern & mode(const StringData &w)
Sets the type of nodes required for write to be successful.
WriteConcern & nodes(int w)
Sets the number of nodes required for write to be successful.
bool requiresConfirmation() const
Whether we need to send getLastError for this WriteConcern.
static const WriteConcern majority
A majority of nodes acknowledges (replica set)
Definition write_concern.h:65
WriteConcern & fsync(bool fsync)
Sets whether fsync is required for write to be successful.
WriteConcern & journal(bool j)
Sets whether journal is required for write to be successful.
static const WriteConcern journaled
A single node acknowledges the write operation was committed to journal.
Definition write_concern.h:59
BSON classes.
the main MongoDB namespace
Definition bulk_operation_builder.h:24