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:
1 parent
a0e9acce95
commit
91c77e53c4
18 files changed
+518
-5
No files matched your search
@@ -63,6 +63,14 @@ struct MongoServerVersionRequest {
|
||||
database: Option<String>,
|
||||
}
|
||||
|
||||
#[derive(Deserialize)]
|
||||
struct MongoCollectionStatsRequest {
|
||||
connection_name: String,
|
||||
database: Option<String>,
|
||||
collection: String,
|
||||
scale: Option<serde_json::Number>,
|
||||
}
|
||||
|
||||
#[derive(Deserialize)]
|
||||
struct MongoAggregateDocumentsRequest {
|
||||
connection_name: String,
|
||||
@@ -187,6 +195,8 @@ pub fn start(app_handle: AppHandle, state: Arc<AppState>, data_dir: PathBuf) {
|
||||
handle_mongo_find_documents_data(&st, body, &mut stream).await;
|
||||
} else if first_line.starts_with("POST /data/mongo/server-version") {
|
||||
handle_mongo_server_version_data(&st, body, &mut stream).await;
|
||||
} else if first_line.starts_with("POST /data/mongo/collection-stats") {
|
||||
handle_mongo_collection_stats_data(&st, body, &mut stream).await;
|
||||
} else if first_line.starts_with("POST /data/mongo/aggregate-documents") {
|
||||
handle_mongo_aggregate_documents_data(&st, body, &mut stream).await;
|
||||
} else if first_line.starts_with("POST /data/mongo/create-index") {
|
||||
@@ -505,6 +515,27 @@ async fn handle_mongo_server_version_data(state: &Arc<AppState>, body: &str, str
|
||||
}
|
||||
}
|
||||
|
||||
async fn handle_mongo_collection_stats_data(state: &Arc<AppState>, body: &str, stream: &mut tokio::net::TcpStream) {
|
||||
let req: MongoCollectionStatsRequest = match serde_json::from_str(body) {
|
||||
Ok(r) => r,
|
||||
Err(_) => {
|
||||
respond_error(stream, "400 Bad Request", "Invalid JSON").await;
|
||||
return;
|
||||
}
|
||||
};
|
||||
let Some((pool_key, database, _connection_id)) =
|
||||
resolve_mongo_pool_key(state, &req.connection_name, req.database, stream).await
|
||||
else {
|
||||
return;
|
||||
};
|
||||
match dbx_core::mongo_ops::mongo_collection_stats_core(state, &pool_key, &database, &req.collection, req.scale)
|
||||
.await
|
||||
{
|
||||
Ok(result) => respond_json(stream, &result).await,
|
||||
Err(e) => respond_error(stream, "500 Internal Server Error", &e).await,
|
||||
}
|
||||
}
|
||||
|
||||
async fn handle_mongo_aggregate_documents_data(state: &Arc<AppState>, body: &str, stream: &mut tokio::net::TcpStream) {
|
||||
let req: MongoAggregateDocumentsRequest = match serde_json::from_str(body) {
|
||||
Ok(r) => r,
|
||||
|
||||
@@ -122,6 +122,24 @@ pub async fn mongo_server_version(
|
||||
.await
|
||||
}
|
||||
|
||||
#[tauri::command]
|
||||
pub async fn mongo_collection_stats(
|
||||
state: State<'_, Arc<AppState>>,
|
||||
connection_id: String,
|
||||
database: String,
|
||||
collection: String,
|
||||
scale: Option<serde_json::Number>,
|
||||
execution_id: Option<String>,
|
||||
) -> Result<dbx_core::db::mongo_driver::MongoCollectionStatsResult, String> {
|
||||
let app = state.inner().clone();
|
||||
run_cancellable(
|
||||
&app,
|
||||
execution_id,
|
||||
dbx_core::mongo_ops::mongo_collection_stats_core(&app, &connection_id, &database, &collection, scale),
|
||||
)
|
||||
.await
|
||||
}
|
||||
|
||||
#[tauri::command]
|
||||
pub async fn mongo_aggregate_documents(
|
||||
state: State<'_, Arc<AppState>>,
|
||||
|
||||
Reference in new issue
Block a user