Skip to content

[Bug] mongo 3.4 下执行js脚本报错 Use MongoDB-specific commands #3050

Open

Description

@snail-devx

数据库类型和版本

mongo 3.4

问题描述

测试脚本如下:

for(var index=0;index<1000;index++){
  db.large_test.insertOne({_id:index})
}

@t8y2 @CN-Scars mongodb数据库下,执行js自定义的需求挺多的,这个错和我之间提的drop、dropIndexes、createIndex 类似,都是dbx面未支持这类语法。

而类似这样的mongo指令非常多,挨个适配工作量太大,而且难免疏漏
对此我的建议是:白名单逻辑
1、默认所有脚本都转执行结果都原样数据,或者尝试json输出,然后将查询、聚合这类可以转换确定返回结构的命名做查询结果表格适配
2、这样做的好处:不用针对mongo数据库的每个指令做适配,先都放开,哪些需要特定渲染(如表格)的时候再独立适配
3、在适配其他数据库的时候,也有同样的问题,才开始没适配好时,如何让它至少可用;比如 #2972

Image

DBX 版本

0.5.51

操作系统

Windows

优先级(是否紧急)

🟠 P1 重要 · 尽快处理

补充信息

No response

Activity

  1. CN-Scars commented on Jul 10, 2026

    @CN-Scars
    Contributor

    @t8y2 我觉得这个建议挺合理的,继续逐条适配 Mongo 命令确实很容易遗漏且繁杂。不过这里还涉及是否支持完整的 Mongo Shell JS,比如 for 循环。想听下你的意见:后续更倾向于完整支持 JS 脚本,还是先做通用命令执行和 JSON/文本兜底?

  2. snail-devx commented on Jul 13, 2026

    @snail-devx
    Author

    @CN-Scars 从功能完整性的角度来说,支持完整 mongo shell js 更好;不过若通用命令执行和这个不冲突的话,个人建议先把通用命令逻辑支持上,毕竟基本的mongodb命令是基架

    感谢聆听 ❤️

  3. q396921921 commented on Oct 19, 2026

    @q396921921
    Contributor

    /claim

  4. dbx-bot commented on Oct 19, 2026

    @dbx-bot

    ✅ @q396921921 已认领 #3050,开始处理吧!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

bugSomething isn't workingdb/mongodbDatabase: MongoDB (Legacy)user-priority/P1User-reported priority: important

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions