feat(mongodb): support collection stats shell commands

Add db.coll.stats() / dataSize() / storageSize(scale) / totalIndexSize()
so these MongoDB shell commands return a result grid instead of the
"Use MongoDB shell-style commands" error (issue #2529).

- backend: collStats via mongo_driver.collection_stats, wired through
  mongo_ops, the dbx-web /mongo/collection-stats route, the tauri
  mongo_collection_stats command, and the MCP data bridge
- node-core: parseMongoCollectionStatsCommand + result formatter and
  executeQuery dispatch (web build + MCP path)
- desktop: mirror the parser/executor/autocomplete in mongoShellCommand.ts,
  queryStore.ts, api/tauri/http facade, and mongoCompletion.ts
- tests for the parser, result formatter, and completion entries

Close #2529
This commit is contained in:
onenewcode authored and GitHub committed 2026-07-03 21:32:29 +08:00
1 parent a0e9acce95
commit 91c77e53c4
18 files changed
+518 -5

No files matched your search

+1
View File
@@ -461,6 +461,7 @@ async fn main() {
.route("/document-store/delete-document", post(routes::document_store::delete_document))
.route("/mongo/find-documents", post(routes::mongo::find_documents))
.route("/mongo/server-version", post(routes::mongo::server_version))
.route("/mongo/collection-stats", post(routes::mongo::collection_stats))
.route("/mongo/aggregate-documents", post(routes::mongo::aggregate_documents))
.route("/mongo/create-index", post(routes::mongo::create_index))
.route("/mongo/drop-indexes", post(routes::mongo::drop_indexes))
+29
View File
@@ -86,6 +86,16 @@ pub struct MongoServerVersionRequest {
pub execution_id: Option<String>,
}
#[derive(Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct MongoCollectionStatsRequest {
pub connection_id: String,
pub database: String,
pub collection: String,
pub scale: Option<serde_json::Number>,
pub execution_id: Option<String>,
}
#[derive(Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct MongoAggregateRequest {
@@ -288,6 +298,25 @@ pub async fn server_version(
Ok(Json(serde_json::to_value(result).map_err(|e| AppError(e.to_string()))?))
}
pub async fn collection_stats(
State(state): State<Arc<WebState>>,
Json(req): Json<MongoCollectionStatsRequest>,
) -> Result<Json<serde_json::Value>, AppError> {
let result = run_cancellable(
&state,
req.execution_id.clone(),
dbx_core::mongo_ops::mongo_collection_stats_core(
&state.app,
&req.connection_id,
&req.database,
&req.collection,
req.scale,
),
)
.await?;
Ok(Json(serde_json::to_value(result).map_err(|e| AppError(e.to_string()))?))
}
pub async fn aggregate_documents(
State(state): State<Arc<WebState>>,
Json(req): Json<MongoAggregateRequest>,