Drop Collection
Drop the specified collection and all its containing documents. Specify an empty document
in the payload to satisfy payload requirements. If you wish to also remove all version history documents for the dropped collection, specify clearVersionHistory
true
in the document
(revision history documents will be removed asynchronously). Specify the write concern settings in the optional options
sub-document.
Data models that represents the payload to be submitted to the service for retrieving aggregated information.
//
// Created by Rakesh on 13/12/2024.
//
#pragma once
#include "../../options/dropcollection.hpp"
#include "action.hpp"
namespace spt::mongoservice::api::model::request
{
struct DropCollection
{
struct Document
{
bool operator==(const Document&) const = default;
BEGIN_VISITABLES(Document);
VISITABLE_DIRECT_INIT(bool, clearVersionHistory, {false});
END_VISITABLES;
};
DropCollection() = default;
~DropCollection() = default;
DropCollection(DropCollection&&) = default;
DropCollection& operator=(DropCollection&&) = default;
DropCollection(const DropCollection&) = delete;
DropCollection& operator=(const DropCollection&) = delete;
BEGIN_VISITABLES(DropCollection);
VISITABLE(Document, document);
VISITABLE(std::optional<options::DropCollection>, options);
VISITABLE(std::string, database);
VISITABLE(std::string, collection);
VISITABLE(std::string, application);
VISITABLE(std::string, correlationId);
VISITABLE_DIRECT_INIT(Action, action, {Action::dropCollection});
VISITABLE_DIRECT_INIT(bool, skipMetric, {false});
END_VISITABLES;
};
}
Data models that represents the payloads the service responds with when returning matching aggregated information.
//
// Created by Rakesh on 18/12/2024.
//
#pragma once
#if defined __has_include
#if __has_include("../../../common/visit_struct/visit_struct_intrusive.hpp")
#include "../../../common/visit_struct/visit_struct_intrusive.hpp"
#include "../../../common/util/serialise.hpp"
#else
#include <mongo-service/common/visit_struct/visit_struct_intrusive.hpp>
#include <mongo-service/common/util/serialise.hpp>
#endif
#endif
#include <string>
namespace spt::mongoservice::api::model::response
{
struct DropCollection
{
explicit DropCollection( bsoncxx::document::view document ) { util::unmarshall( *this, document ); }
DropCollection() = default;
~DropCollection() = default;
DropCollection(DropCollection&&) = default;
DropCollection& operator=(DropCollection&&) = default;
DropCollection(const DropCollection&) = delete;
DropCollection& operator=(const DropCollection&) = delete;
BEGIN_VISITABLES(DropCollection);
VISITABLE_DIRECT_INIT(bool, dropCollection, {false});
END_VISITABLES;
};
}
Sample code illustrating the index action.
#include <mongo-service/api/repository/repository.hpp>
#include <log/NanoLog.hpp>
int main()
{
using namespace spt::mongoservice::api;
auto remove = model::request::DropCollection{};
remove.document.clearVersionHistory = true;
remove.database = "test";
remove.collection = "test";
auto result = repository::dropCollection( remove );
if ( !result.has_value() )
{
LOG_WARN << "Error dropping collection. " << magic_enum::enum_name( result.error().cause ) << ". " << result.error().message;
}
}
Last modified: 18 February 2025