|
@@ -82,8 +82,17 @@ bool execCommand(smartbotic::database::Client& client,
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
if (cmd == "find") {
|
|
if (cmd == "find") {
|
|
|
- if (params.empty()) { printError("usage: find <collection>"); return false; }
|
|
|
|
|
- auto docs = client.find(params[0]);
|
|
|
|
|
|
|
+ if (params.empty()) { printError("usage: find <collection> [--limit N] [--exists FIELD]"); return false; }
|
|
|
|
|
+ smartbotic::database::Client::QueryOptions opts;
|
|
|
|
|
+ opts.limit = 100;
|
|
|
|
|
+ for (size_t i = 1; i < params.size(); ++i) {
|
|
|
|
|
+ if (params[i] == "--limit" && i + 1 < params.size()) {
|
|
|
|
|
+ opts.limit = static_cast<uint32_t>(std::stoul(params[++i]));
|
|
|
|
|
+ } else if (params[i] == "--exists" && i + 1 < params.size()) {
|
|
|
|
|
+ opts.filters.emplace_back(params[++i], smartbotic::database::Client::FilterOp::EXISTS, true);
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ auto docs = client.find(params[0], opts);
|
|
|
std::cout << C_DIM << "(" << docs.size() << " documents)" << C_RESET << "\n";
|
|
std::cout << C_DIM << "(" << docs.size() << " documents)" << C_RESET << "\n";
|
|
|
for (const auto& doc : docs) {
|
|
for (const auto& doc : docs) {
|
|
|
auto id = doc.value("_id", "");
|
|
auto id = doc.value("_id", "");
|