MongoDB C++ Driver current
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/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/gridfs/bucket.hpp>
27#include <mongocxx/read_preference.hpp>
28#include <mongocxx/write_concern.hpp>
29
30#include <mongocxx/config/prelude.hpp>
31
32namespace mongocxx {
33inline namespace v_noabi {
34class client_encryption;
35class client;
36class collection;
37
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
107 cursor aggregate(const pipeline& pipeline,
108 const options::aggregate& options = options::aggregate());
109
133 cursor aggregate(const client_session& session,
134 const pipeline& pipeline,
135 const options::aggregate& options = options::aggregate());
139
152 bsoncxx::document::value run_command(bsoncxx::document::view_or_value command);
153
165 bsoncxx::document::value run_command(const client_session& session,
166 bsoncxx::document::view_or_value command);
167
179 bsoncxx::document::value run_command(bsoncxx::document::view_or_value command,
180 uint32_t server_id);
184
207 class collection create_collection(stdx::string_view name,
208 bsoncxx::document::view_or_value collection_options = {},
209 const stdx::optional<write_concern>& write_concern = {});
210
233 class collection create_collection(const client_session& session,
234 stdx::string_view name,
235 bsoncxx::document::view_or_value collection_options = {},
236 const stdx::optional<write_concern>& write_concern = {});
237
259 MONGOCXX_DEPRECATED class collection create_collection(
260 bsoncxx::string::view_or_value name,
261 const options::create_collection_deprecated& collection_options,
262 const stdx::optional<write_concern>& write_concern = {}) {
263 return create_collection_deprecated(name, collection_options, write_concern);
264 }
265
266 class collection create_collection_deprecated(
267 bsoncxx::string::view_or_value name,
268 const options::create_collection_deprecated& collection_options,
269 const stdx::optional<write_concern>& write_concern = {});
270
294 MONGOCXX_DEPRECATED class collection create_collection(
295 const client_session& session,
296 bsoncxx::string::view_or_value name,
297 const options::create_collection_deprecated& collection_options,
298 const stdx::optional<write_concern>& write_concern = {}) {
299 return create_collection_deprecated(session, name, collection_options, write_concern);
300 }
301
325 class collection create_collection_deprecated(
326 const client_session& session,
327 bsoncxx::string::view_or_value name,
328 const options::create_collection_deprecated& collection_options,
329 const stdx::optional<write_concern>& write_concern = {});
330
334
350 void drop(const bsoncxx::stdx::optional<mongocxx::write_concern>& write_concern = {});
351
367 void drop(const client_session& session,
368 const bsoncxx::stdx::optional<mongocxx::write_concern>& write_concern = {});
372
383 bool has_collection(bsoncxx::string::view_or_value name) const;
384
397 cursor list_collections(bsoncxx::document::view_or_value filter = {});
398
412 bsoncxx::document::view_or_value filter = {});
413
427 std::vector<std::string> list_collection_names(bsoncxx::document::view_or_value filter = {});
428
444 std::vector<std::string> list_collection_names(const client_session& session,
445 bsoncxx::document::view_or_value filter = {});
446
450
456 stdx::string_view name() const;
457
471
481
494
503
512
519
527 class collection collection(bsoncxx::string::view_or_value name) const;
528
537 MONGOCXX_INLINE class collection operator[](bsoncxx::string::view_or_value name) const;
538
553 class gridfs::bucket gridfs_bucket(
554 const options::gridfs::bucket& options = options::gridfs::bucket()) const;
555
570 change_stream watch(const options::change_stream& options = {});
571
583 change_stream watch(const client_session& session, const options::change_stream& options = {});
584
601 change_stream watch(const pipeline& pipe, const options::change_stream& options = {});
602
618 change_stream watch(const client_session& session,
619 const pipeline& pipe,
620 const options::change_stream& options = {});
621
625
626 private:
627 friend class client_encryption;
628 friend class client;
629 friend class collection;
630
631 MONGOCXX_PRIVATE database(const class client& client, bsoncxx::string::view_or_value name);
632
633 MONGOCXX_PRIVATE cursor _aggregate(const client_session* session,
634 const pipeline& pipeline,
635 const options::aggregate& options);
636
637 MONGOCXX_PRIVATE bsoncxx::document::value _run_command(
638 const client_session* session, bsoncxx::document::view_or_value command);
639
640 MONGOCXX_PRIVATE class collection _create_collection(
641 const client_session* session,
642 stdx::string_view name,
643 bsoncxx::document::view_or_value collection_options,
644 const stdx::optional<class write_concern>& write_concern);
645
646 MONGOCXX_PRIVATE class collection _create_collection_deprecated(
647 const client_session* session,
648 bsoncxx::string::view_or_value name,
649 const options::create_collection_deprecated& collection_options,
650 const stdx::optional<class write_concern>& write_concern);
651
652 MONGOCXX_PRIVATE cursor _list_collections(const client_session* session,
653 bsoncxx::document::view_or_value filter);
654
655 MONGOCXX_PRIVATE std::vector<std::string> _list_collection_names(
656 const client_session* session, bsoncxx::document::view_or_value filter);
657
658 MONGOCXX_PRIVATE void _drop(
659 const client_session* session,
660 const bsoncxx::stdx::optional<mongocxx::write_concern>& write_concern);
661
662 MONGOCXX_PRIVATE change_stream _watch(const client_session* session,
663 const pipeline& pipe,
664 const options::change_stream& options);
665
666 class MONGOCXX_PRIVATE impl;
667
668 MONGOCXX_PRIVATE impl& _get_impl();
669 MONGOCXX_PRIVATE const impl& _get_impl() const;
670
671 std::unique_ptr<impl> _impl;
672};
673
674MONGOCXX_INLINE collection database::operator[](bsoncxx::string::view_or_value name) const {
675 return collection(name);
676}
677
678} // namespace v_noabi
679} // namespace mongocxx
680
681#include <mongocxx/config/postlude.hpp>
Class representing a MongoDB change stream.
Definition change_stream.hpp:33
Class supporting operations for MongoDB Client-Side Field Level Encryption.
Definition client_encryption.hpp:38
Use a session for a sequence of operations, optionally with either causal consistency or snapshots.
Definition client_session.hpp:40
Class representing a client connection to MongoDB.
Definition client.hpp:54
Class representing server side document groupings within a MongoDB database.
Definition collection.hpp:85
Class representing a pointer to the result set of a query on a MongoDB server.
Definition cursor.hpp:36
Class representing a MongoDB database.
Definition database.hpp:44
std::vector< std::string > list_collection_names(const client_session &session, bsoncxx::document::view_or_value filter={})
Enumerates the collection names in this database.
stdx::string_view name() const
Get the name of this database.
void drop(const client_session &session, const bsoncxx::stdx::optional< mongocxx::write_concern > &write_concern={})
Drops the database and all its collections.
cursor list_collections(const client_session &session, bsoncxx::document::view_or_value filter={})
Enumerates the collections in this database.
database() noexcept
Default constructs a new database.
void drop(const bsoncxx::stdx::optional< mongocxx::write_concern > &write_concern={})
Drops the database and all its collections.
void write_concern(class write_concern wc)
Sets the write_concern for this database.
std::vector< std::string > list_collection_names(bsoncxx::document::view_or_value filter={})
Enumerates the collection names in this database.
cursor list_collections(bsoncxx::document::view_or_value filter={})
Enumerates the collections in this database.
bool has_collection(bsoncxx::string::view_or_value name) const
Checks whether this database contains a collection having the given name.
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.
Class representing a GridFS bucket.
Definition bucket.hpp:62
Class representing the optional arguments to a MongoDB createCollection command.
Definition create_collection.hpp:35
Class representing a MongoDB aggregation pipeline.
Definition pipeline.hpp:37
A class to represent the read concern.
Definition read_concern.hpp:57
Class representing a preference for how the driver routes read operations to members of a replica set...
Definition read_preference.hpp:67
Class representing the server-side requirement for reporting the success of a write operation.
Definition write_concern.hpp:59
The top-level namespace for bsoncxx library entities.
Definition element.hpp:24
The top-level namespace for mongocxx library entities.
Definition bulk_write.hpp:24