MongoDB C++ Driver  mongocxx-3.3.1
All Classes Namespaces Functions Enumerations Enumerator Friends Pages
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/client_session.hpp>
23 #include <mongocxx/collection.hpp>
24 #include <mongocxx/gridfs/bucket.hpp>
25 #include <mongocxx/options/create_collection.hpp>
26 #include <mongocxx/options/create_view.hpp>
27 #include <mongocxx/options/gridfs/bucket.hpp>
28 #include <mongocxx/options/modify_collection.hpp>
29 #include <mongocxx/read_preference.hpp>
30 #include <mongocxx/write_concern.hpp>
31 
32 #include <mongocxx/config/prelude.hpp>
33 
34 namespace mongocxx {
35 MONGOCXX_INLINE_NAMESPACE_BEGIN
36 
37 class client;
38 
47 class MONGOCXX_API database {
48  public:
54  database() noexcept;
55 
59  database(database&&) noexcept;
60 
64  database& operator=(database&&) noexcept;
65 
69  database(const database&);
70 
74  database& operator=(const database&);
75 
79  ~database();
80 
85  explicit operator bool() const noexcept;
86 
100 
112  bsoncxx::document::value run_command(const client_session& session,
117 
137  class collection create_collection(
138  bsoncxx::string::view_or_value name,
139  const options::create_collection& collection_options = options::create_collection{},
140  const stdx::optional<write_concern>& write_concern = {});
141 
161  class collection create_collection(
162  const client_session& session,
164  const options::create_collection& collection_options = options::create_collection{},
165  const stdx::optional<write_concern>& write_concern = {});
169 
183  class collection create_view(bsoncxx::string::view_or_value name,
185  const options::create_view& options = options::create_view());
186 
201  MONGOCXX_DEPRECATED bsoncxx::document::value modify_collection(
202  stdx::string_view name,
203  const options::modify_collection& options = options::modify_collection());
204 
205  bsoncxx::document::value modify_collection_deprecated(
206  stdx::string_view name,
207  const options::modify_collection& options = options::modify_collection());
208 
224  void drop(const bsoncxx::stdx::optional<mongocxx::write_concern>& write_concern = {});
225 
241  void drop(const client_session& session,
242  const bsoncxx::stdx::optional<mongocxx::write_concern>& write_concern = {});
246 
257  bool has_collection(bsoncxx::string::view_or_value name) const;
258 
274  cursor list_collections(bsoncxx::document::view_or_value filter = {});
275 
291  cursor list_collections(const client_session& session,
292  bsoncxx::document::view_or_value filter = {});
296 
302  stdx::string_view name() const;
303 
316  void read_concern(class read_concern rc);
317 
326  class read_concern read_concern() const;
327 
339  void read_preference(class read_preference rp);
340 
348  class read_preference read_preference() const;
349 
357  void write_concern(class write_concern wc);
358 
364  class write_concern write_concern() const;
365 
373  class collection collection(bsoncxx::string::view_or_value name) const;
374 
383  MONGOCXX_INLINE class collection operator[](bsoncxx::string::view_or_value name) const;
384 
399  class gridfs::bucket gridfs_bucket(
400  const options::gridfs::bucket& options = options::gridfs::bucket()) const;
401 
402  private:
403  friend class client;
404  friend class collection;
405 
406  MONGOCXX_PRIVATE database(const class client& client, bsoncxx::string::view_or_value name);
407 
408  MONGOCXX_PRIVATE bsoncxx::document::value _run_command(
409  const client_session* session, bsoncxx::document::view_or_value command);
410 
411  MONGOCXX_PRIVATE class collection _create_collection(
412  const client_session* session,
413  bsoncxx::string::view_or_value name,
414  const options::create_collection& collection_options,
415  const stdx::optional<class write_concern>& write_concern);
416 
417  MONGOCXX_PRIVATE cursor _list_collections(const client_session* session,
418  bsoncxx::document::view_or_value filter);
419 
420  MONGOCXX_PRIVATE void _drop(
421  const client_session* session,
422  const bsoncxx::stdx::optional<mongocxx::write_concern>& write_concern);
423 
424  class MONGOCXX_PRIVATE impl;
425 
426  MONGOCXX_PRIVATE impl& _get_impl();
427  MONGOCXX_PRIVATE const impl& _get_impl() const;
428 
429  std::unique_ptr<impl> _impl;
430 };
431 
432 MONGOCXX_INLINE collection database::operator[](bsoncxx::string::view_or_value name) const {
433  return collection(name);
434 }
435 
436 MONGOCXX_INLINE_NAMESPACE_END
437 } // namespace mongocxx
438 
439 #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:24
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:57
Use a session for a sequence of operations, optionally with causal consistency.
Definition: client_session.hpp:38
Class representing a GridFS bucket.
Definition: bucket.hpp:62
Class representing a MongoDB database.
Definition: database.hpp:47
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:87