feat(mongodb): 支持文档可视化编辑与删除

- 前端表格预览使用 _id 构建 MongoDB 行定位,并隐藏 typed ObjectID locator

- 后端 ApplyChanges 支持 MongoDB 更新、单删和批量删除,区分 ObjectID 与字符串 _id

- 补充 DataViewer、DataGrid 与双版本 Mongo driver 回归测试

Refs #458
This commit is contained in:
Syngnat
2026-05-13 21:48:14 +08:00
parent 2ad2f26b2b
commit 01eb2c25e0
10 changed files with 547 additions and 52 deletions

View File

@@ -1,6 +1,6 @@
import { describe, expect, it } from 'vitest';
import { applyMongoQueryAutoLimit, convertMongoShellToJsonCommand } from './mongodb';
import { applyMongoQueryAutoLimit, buildMongoFindCommand, convertMongoShellToJsonCommand } from './mongodb';
const parseCommand = (command: string | undefined) => JSON.parse(command || '{}');
@@ -120,3 +120,17 @@ describe('applyMongoQueryAutoLimit', () => {
expect(applyMongoQueryAutoLimit('db.users.find({})', 500).applied).toBe(false);
});
});
describe('buildMongoFindCommand', () => {
it('marks DataViewer Mongo find commands to include typed _id locator', () => {
expect(parseCommand(buildMongoFindCommand({
collection: 'users',
filter: {},
includeObjectIDLocator: true,
}))).toEqual({
find: 'users',
filter: {},
__gonaviIncludeObjectIDLocator: true,
});
});
});

View File

@@ -651,11 +651,15 @@ export const buildMongoFindCommand = (params: {
limit?: number;
skip?: number;
projection?: Record<string, unknown>;
includeObjectIDLocator?: boolean;
}): string => {
const command: Record<string, unknown> = {
find: String(params.collection || '').trim(),
filter: params.filter || {},
};
if (params.includeObjectIDLocator) {
command.__gonaviIncludeObjectIDLocator = true;
}
if (params.projection && Object.keys(params.projection).length > 0) {
command.projection = params.projection;
}