MongoDB C++ Driver  mongocxx-3.0.2
database.hpp
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 #pragma once
16 
17 #include <memory>
18 #include <string>
19 
20 #include <bsoncxx/document/view_or_value.hpp>
21 #include <bsoncxx/string/view_or_value.hpp>
22 #include <mongocxx/collection.hpp>
23 #include <mongocxx/options/modify_collection.hpp>
24 #include <mongocxx/options/create_collection.hpp>
25 #include <mongocxx/write_concern.hpp>
26 #include <mongocxx/read_preference.hpp>
27 
28 #include <mongocxx/config/prelude.hpp>
29 
30 namespace mongocxx {
31 MONGOCXX_INLINE_NAMESPACE_BEGIN
32 
33 class client;
34 
43 class MONGOCXX_API database {
44  public:
50  database() noexcept;
51 
55  database(database&&) noexcept;
56 
60  database& operator=(database&&) noexcept;
61 
65  database(const database&);
66 
70  database& operator=(const database&);
71 
75  ~database();
76 
81  explicit operator bool() const noexcept;
82 
94 
105  class collection create_collection(
106  bsoncxx::string::view_or_value name,
108 
119  bsoncxx::document::value modify_collection(
120  stdx::string_view name,
121  const options::modify_collection& options = options::modify_collection());
122 
127  //
130  void drop();
131 
142  bool has_collection(bsoncxx::string::view_or_value name) const;
143 
157  cursor list_collections(bsoncxx::document::view_or_value filter = {});
158 
164  stdx::string_view name() const;
165 
178  void read_concern(class read_concern rc);
179 
188  class read_concern read_concern() const;
189 
201  void read_preference(class read_preference rp);
202 
210  class read_preference read_preference() const;
211 
219  void write_concern(class write_concern wc);
220 
226  class write_concern write_concern() const;
227 
235  class collection collection(bsoncxx::string::view_or_value name) const;
236 
245  MONGOCXX_INLINE class collection operator[](bsoncxx::string::view_or_value name) const;
246 
247  private:
248  friend class client;
249  friend class collection;
250 
251  MONGOCXX_PRIVATE database(const class client& client, bsoncxx::string::view_or_value name);
252 
253  class MONGOCXX_PRIVATE impl;
254 
255  MONGOCXX_PRIVATE impl& _get_impl();
256  MONGOCXX_PRIVATE const impl& _get_impl() const;
257 
258  std::unique_ptr<impl> _impl;
259 };
260 
261 MONGOCXX_INLINE collection database::operator[](bsoncxx::string::view_or_value name) const {
262  return collection(name);
263 }
264 
265 MONGOCXX_INLINE_NAMESPACE_END
266 } // namespace mongocxx
267 
268 #include <mongocxx/config/postlude.hpp>
Class representing the optional arguments to a MongoDB createCollection command.
Definition: create_collection.hpp:31
Definition: bulk_write.hpp:22
A read-only BSON document that owns its underlying buffer.
Definition: value.hpp:33
Class representing a pointer to the result set of a query on a MongoDB server.
Definition: cursor.hpp:35
Class representing a client connection to MongoDB.
Definition: client.hpp:49
Class representing a MongoDB database.
Definition: database.hpp:43
Class representing a preference for how the driver routes read operations to members of a replica set...
Definition: read_preference.hpp:54
A class to represent the read concern.
Definition: read_concern.hpp:46
Class representing the server-side requirement for reporting the success of a write operation...
Definition: write_concern.hpp:54
Class representing server side document groupings within a MongoDB database.
Definition: collection.hpp:74