mirror of
https://github.com/Syngnat/GoNavi.git
synced 2026-08-05 22:03:36 +08:00
✨ feat(mongodb): 支持文档可视化编辑与删除
- 前端表格预览使用 _id 构建 MongoDB 行定位,并隐藏 typed ObjectID locator - 后端 ApplyChanges 支持 MongoDB 更新、单删和批量删除,区分 ObjectID 与字符串 _id - 补充 DataViewer、DataGrid 与双版本 Mongo driver 回归测试 Refs #458
This commit is contained in:
@@ -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,
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user