Delete()
This operation deletes entities by a filtering expression or an ID array.
Status Delete(const DeleteRequest& request, DeleteResponse& response)
Request Syntax
auto request = DeleteRequest()
.WithDatabaseName(db_name)
.WithCollectionName(collection_name)
.WithPartitionName(partition_name)
.WithFilter(filter)
.WithFilterTemplates(value)
.WithIDs(id_array);
REQUEST METHODS:
WithDatabaseName(const std::string& db_name)Sets the target database name. The default database applies if it is empty.
WithCollectionName(const std::string& collection_name)Sets the name of the collection.
WithPartitionName(const std::string& partition_name)Sets the names of the partitions. If it is empty, the default partition applies.
WithFilter(const std::string& filter)Sets a filter expression.
AddFilterTemplate(std::string key, nlohmann::json&& filter_template)Adds a filter template. This takes effect only if
WithFilter()is set. Read this page for more about filter templating.WithFilterTemplates(std::unordered_map<std::string, nlohmann::json>&& filter_templates)Sets filter templates. This takes effect only if
WithFilter()is set. Read this page for more about filter templating.WithIDs(std::vector<int64_t>&& id_array)Sets a set of integer primary keys. This takes effect only if
WithFilter()is empty.
RETURNS:
Status with DeleteResponse
Check status.IsOk() to confirm success.
DmlResults
This class carries the outcome of a data-mutation operation (insert, upsert, or delete). It is accessed via Results() on InsertResponse, UpsertResponse, or DeleteResponse.
const DmlResults& results = response.Results();
METHODS:
const IDArray& IdArray() constThe IDs of the entities that were inserted, upserted, or deleted. For auto-ID collections the server fills this in after insert. See IDArray for how to read integer or string IDs.
uint64_t Timestamp() constServer-side operation timestamp. Can be passed as the
guarantee_timestampin subsequent search or query calls to ensure read-your-writes consistency.uint64_t InsertCount() constNumber of rows that were inserted. Populated for
InsertResponseandUpsertResponse.uint64_t DeleteCount() constNumber of rows that were deleted. Populated for
DeleteResponseandUpsertResponse.uint64_t UpsertCount() constNumber of rows that were upserted (inserted as new or replaced existing). Populated for
UpsertResponse.
EXCEPTIONS:
StatusCode
Check
status.Code()andstatus.Message()for error details.
Example
#include "milvus/MilvusClientV2.h"
auto client = milvus::MilvusClientV2::Create();
milvus::ConnectParam connect_param{"http://localhost:19530", "root:Milvus"};
auto status = client->Connect(connect_param);
if (!status.IsOk()) {
std::cout << status.Message() << std::endl;
}
milvus::DeleteResponse resp_delete;
status = client->Delete(milvus::DeleteRequest()
.WithCollectionName(collection_name)
.WithPartitionName(partition_name)
.WithFilter(field_id + "== 5"),
resp_delete);
if (!status.IsOk()) {
std::cout << status.Message() << std::endl;
}