validate #
Validates data against existing validation rules.
Documents are always valid if no validation rules are defined on the provided index and collection.
This request does not store the document.
Signature #
bool validate(
const std::string& index,
const std::string& collection,
const std::string& document);
bool validate(
const std::string& index,
const std::string& collection,
const std::string& document,
const kuzzleio::query_options& options);
Arguments #
Argument | Type | Description |
---|---|---|
index | const std::string& | Index name |
collection | const std::string& | Collection name |
document | const std::string& | JSON string representing the document |
options | kuzzleio::query_options* | Query options |
options #
Additional query options
Option | Type (default) | Description |
---|---|---|
queuable | bool ( true ) | If true, queues the request during downtime, until connected to Kuzzle again |
Return #
A boolean set to true if the document is valid and false otherwise.
Exceptions #
Throws a kuzzleio::KuzzleException
if there is an error. See how to handle errors.
Usage #
try {
bool valid = kuzzle->document->validate("nyc-open-data", "yellow-taxi", R"({
"capacity": 4
})");
if (valid) {
std::cout << "The document is valid" << std::endl;
}
} catch (kuzzleio::KuzzleException& e) {
std::cerr << e.what() << std::endl;
}
Edit this page on Github(opens new window)