MongoDB C++ Driver mongocxx-3.1.1
Loading...
Searching...
No Matches
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/options/create_view.hpp>
26#include <mongocxx/write_concern.hpp>
27#include <mongocxx/read_preference.hpp>
28
29#include <mongocxx/config/prelude.hpp>
30
31namespace mongocxx {
32MONGOCXX_INLINE_NAMESPACE_BEGIN
33
34class client;
35
44class MONGOCXX_API database {
45 public:
51 database() noexcept;
52
56 database(database&&) noexcept;
57
61 database& operator=(database&&) noexcept;
62
67
71 database& operator=(const database&);
72
77
82 explicit operator bool() const noexcept;
83
94 bsoncxx::document::value run_command(bsoncxx::document::view_or_value command);
95
111 class collection create_collection(
112 bsoncxx::string::view_or_value name,
113 const options::create_collection& options = options::create_collection());
114
134 class collection create_view(bsoncxx::string::view_or_value name,
135 bsoncxx::string::view_or_value view_on,
136 const options::create_view& options = options::create_view());
137
152 bsoncxx::document::value modify_collection(
153 stdx::string_view name,
154 const options::modify_collection& options = options::modify_collection());
155
160 //
168 void drop();
169
180 bool has_collection(bsoncxx::string::view_or_value name) const;
181
195 cursor list_collections(bsoncxx::document::view_or_value filter = {});
196
202 stdx::string_view name() const;
203
217
227
240
249
258
265
273 class collection collection(bsoncxx::string::view_or_value name) const;
274
283 MONGOCXX_INLINE class collection operator[](bsoncxx::string::view_or_value name) const;
284
285 private:
286 friend class client;
287 friend class collection;
288
289 MONGOCXX_PRIVATE database(const class client& client, bsoncxx::string::view_or_value name);
290
291 class MONGOCXX_PRIVATE impl;
292
293 MONGOCXX_PRIVATE impl& _get_impl();
294 MONGOCXX_PRIVATE const impl& _get_impl() const;
295
296 std::unique_ptr<impl> _impl;
297};
298
299MONGOCXX_INLINE collection database::operator[](bsoncxx::string::view_or_value name) const {
300 return collection(name);
301}
302
303MONGOCXX_INLINE_NAMESPACE_END
304} // namespace mongocxx
305
306#include <mongocxx/config/postlude.hpp>
Class representing a client connection to MongoDB.
Definition client.hpp:52
Class representing server side document groupings within a MongoDB database.
Definition collection.hpp:74
Class representing a pointer to the result set of a query on a MongoDB server.
Definition cursor.hpp:35
Class representing a MongoDB database.
Definition database.hpp:44
database() noexcept
Default constructs a new database.
stdx::string_view name() const
Get the name of this database.
void write_concern(class write_concern wc)
Sets the write_concern for this database.
void read_concern(class read_concern rc)
Sets the read_concern for this database.
void read_preference(class read_preference rp)
Sets the read_preference for this database.
A class to represent the read concern.
Definition read_concern.hpp:52
Class representing a preference for how the driver routes read operations to members of a replica set...
Definition read_preference.hpp:57
Class representing the server-side requirement for reporting the success of a write operation.
Definition write_concern.hpp:54
Top level namespace for MongoDB C++ BSON functionality.
Definition element.hpp:24
Top level namespace for the MongoDB C++ driver.
Definition bulk_write.hpp:22