fix(mongodb): use dedicated count for legacy collections

This commit is contained in:
Guoyu Su authored and GitHub committed 2026-07-13 13:21:50 +08:00
1 parent 03bc87c77a
commit a99a34b4ab
28 files changed
+916 -19

No files matched your search

+1
View File
@@ -432,6 +432,7 @@ export const mongoDropDatabase = forward("mongoDropDatabase");
export const mongoDropCollection = forward("mongoDropCollection");
export const documentFindDocuments = forward("documentFindDocuments");
export const mongoFindDocuments = forward("mongoFindDocuments");
export const mongoCountDocuments = forward("mongoCountDocuments");
export const mongoServerVersion = forward("mongoServerVersion");
export const mongoAggregateDocuments = forward("mongoAggregateDocuments");
export const mongoCollectionStats = forward("mongoCollectionStats");
+4
View File
@@ -2009,6 +2009,10 @@ export async function documentFindDocuments(connectionId: string, database: stri
return post("/api/document-store/find-documents", { connectionId, database, collection, skip, limit, filter, projection, sort, executionId });
}
export async function mongoCountDocuments(connectionId: string, database: string, collection: string, filter?: string, mode?: "accurate" | "legacy", executionId?: string): Promise<number> {
return post("/api/mongo/count-documents", { connectionId, database, collection, filter, mode, executionId });
}
export async function documentListGridFsFiles(connectionId: string, database: string, bucket: string, filter?: string, sort?: string): Promise<MongoGridFsFileInfo[]> {
return post("/api/document-store/list-gridfs-files", { connectionId, database, bucket, filter, sort });
}
+4
View File
@@ -1792,6 +1792,10 @@ export async function documentFindDocuments(connectionId: string, database: stri
return invoke("document_find_documents", { connectionId, database, collection, skip, limit, filter, projection, sort, executionId });
}
export async function mongoCountDocuments(connectionId: string, database: string, collection: string, filter?: string, mode?: "accurate" | "legacy", executionId?: string): Promise<number> {
return invoke("mongo_count_documents", { connectionId, database, collection, filter, mode, executionId });
}
export async function documentListGridFsFiles(connectionId: string, database: string, bucket: string, filter?: string, sort?: string): Promise<MongoGridFsFileInfo[]> {
return invoke("document_list_gridfs_files", { connectionId, database, bucket, filter, sort });
}
@@ -12,6 +12,7 @@ export interface MongoFindCommand {
export interface MongoCountDocumentsCommand {
collection: string;
filter: string;
mode: "accurate" | "legacy";
}
export interface MongoAggregateCommand {
@@ -145,8 +146,6 @@ export function applyMongoFindSort(input: string, column: string, direction: "as
export function parseMongoCountDocumentsCommand(input: string): MongoCountDocumentsCommand | null {
const source = input.trim().replace(/;$/, "").trim();
// Accept deprecated Mongo shell count helpers for old server workflows, but
// keep DBX's internal execution mapped to the countDocuments result shape.
return parseCollectionCountCommand(source, "countDocuments") ?? parseCollectionCountCommand(source, "count") ?? parseFindCountCommand(source);
}
@@ -166,6 +165,7 @@ function parseCollectionCountCommand(source: string, method: "countDocuments" |
return {
collection: target.collection,
filter,
mode: method === "countDocuments" ? "accurate" : "legacy",
};
}
@@ -188,6 +188,7 @@ function parseFindCountCommand(source: string): MongoCountDocumentsCommand | nul
return {
collection: target.collection,
filter,
mode: "legacy",
};
}