Procházet zdrojové kódy

feat(cli): add --limit and --exists flags to `find` for admin pagination

`find <collection>` previously hardcoded QueryOptions defaults (limit=100,
no filters), which caps at 100 docs and makes bulk admin passes impossible
on collections larger than that. Anything past the first 100 was
inaccessible from the CLI alone.

Accept:
- `--limit N`  pass-through to QueryOptions::limit
- `--exists FIELD`  build a FilterOp::EXISTS filter, bool(true) value

Leaves every other default untouched; no-args behavior matches prior output
exactly.

Used this to scrub a retired app-level `created_at` field from ~2800
messages on a live instance in one pass (`find messages --limit 50000
--exists created_at`).
fszontagh před 3 měsíci
rodič
revize
618bfa0c9d
1 změnil soubory, kde provedl 11 přidání a 2 odebrání
  1. 11 2
      cli/main.cpp

+ 11 - 2
cli/main.cpp

@@ -82,8 +82,17 @@ bool execCommand(smartbotic::database::Client& client,
         }
 
         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";
             for (const auto& doc : docs) {
                 auto id = doc.value("_id", "");