MongoDB C++ Driver  mongocxx-3.2.0
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/gridfs/bucket.hpp>
24 #include <mongocxx/options/create_collection.hpp>
25 #include <mongocxx/options/create_view.hpp>
26 #include <mongocxx/options/gridfs/bucket.hpp>
27 #include <mongocxx/options/modify_collection.hpp>
28 #include <mongocxx/read_preference.hpp>
29 #include <mongocxx/write_concern.hpp>
30 
31 #include <mongocxx/config/prelude.hpp>
32 
33 namespace mongocxx {
34 MONGOCXX_INLINE_NAMESPACE_BEGIN
35 
36 class client;
37 
46 class MONGOCXX_API database {
47  public:
53  database() noexcept;
54 
58  database(database&&) noexcept;
59 
63  database& operator=(database&&) noexcept;
64 
68  database(const database&);
69 
73  database& operator=(const database&);
74 
78  ~database();
79 
84  explicit operator bool() const noexcept;
85 
97 
115  class collection create_collection(
116  bsoncxx::string::view_or_value name,
117  const options::create_collection& collection_options = options::create_collection{},
118  const stdx::optional<write_concern>& write_concern = {});
119 
134  class collection create_view(bsoncxx::string::view_or_value name,
136  const options::create_view& options = options::create_view());
137 
152  MONGOCXX_DEPRECATED bsoncxx::document::value modify_collection(
153  stdx::string_view name,
154  const options::modify_collection& options = options::modify_collection());
155 
156  bsoncxx::document::value modify_collection_deprecated(
157  stdx::string_view name,
158  const options::modify_collection& options = options::modify_collection());
159 
173  void drop(const bsoncxx::stdx::optional<mongocxx::write_concern>& write_concern = {});
174 
185  bool has_collection(bsoncxx::string::view_or_value name) const;
186 
200  cursor list_collections(bsoncxx::document::view_or_value filter = {});
201 
207  stdx::string_view name() const;
208 
221  void read_concern(class read_concern rc);
222 
231  class read_concern read_concern() const;
232 
244  void read_preference(class read_preference rp);
245 
253  class read_preference read_preference() const;
254 
262  void write_concern(class write_concern wc);
263 
269  class write_concern write_concern() const;
270 
278  class collection collection(bsoncxx::string::view_or_value name) const;
279 
288  MONGOCXX_INLINE class collection operator[](bsoncxx::string::view_or_value name) const;
289 
304  class gridfs::bucket gridfs_bucket(
305  const options::gridfs::bucket& options = options::gridfs::bucket()) const;
306 
307  private:
308  friend class client;
309  friend class collection;
310 
311  MONGOCXX_PRIVATE database(const class client& client, bsoncxx::string::view_or_value name);
312 
313  class MONGOCXX_PRIVATE impl;
314 
315  MONGOCXX_PRIVATE impl& _get_impl();
316  MONGOCXX_PRIVATE const impl& _get_impl() const;
317 
318  std::unique_ptr<impl> _impl;
319 };
320 
321 MONGOCXX_INLINE collection database::operator[](bsoncxx::string::view_or_value name) const {
322  return collection(name);
323 }
324 
325 MONGOCXX_INLINE_NAMESPACE_END
326 } // namespace mongocxx
327 
328 #include <mongocxx/config/postlude.hpp>
Class representing the optional arguments to a MongoDB createCollection command.
Definition: create_collection.hpp:31
Top level namespace for the MongoDB C++ driver.
Definition: bulk_write.hpp:22
Class representing the optional arguments to a view creation operation.
Definition: create_view.hpp:35
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:36
Class representing a client connection to MongoDB.
Definition: client.hpp:54
Class representing a GridFS bucket.
Definition: bucket.hpp:62
Class representing a MongoDB database.
Definition: database.hpp:46
Class representing a preference for how the driver routes read operations to members of a replica set...
Definition: read_preference.hpp:57
Class representing a view-or-value variant type for strings.
Definition: view_or_value.hpp:36
A class to represent the read concern.
Definition: read_concern.hpp:52
Top level namespace for MongoDB C++ BSON functionality.
Definition: element.hpp:24
Class representing the server-side requirement for reporting the success of a write operation...
Definition: write_concern.hpp:55
Class representing server side document groupings within a MongoDB database.
Definition: collection.hpp:84