"""Offline RockMongo historical configuration audit & modern MongoDB Compass migration verifier."""
import json
VERSION = "CPython 3.12.14 offline MongoDB document/query verifier (mongod absent)"
def audit_rockmongo_config(cfg):
warnings = []
if cfg.get("php_major", 5) >= 7:
warnings.append("incompatible_with_php7_plus_removed_php_mongo_ext")
for user, pwd in cfg.get("admins", {}).items():
if user == "admin" and pwd == "admin":
warnings.append("insecure_default_admin_credentials")
return {
"host_count": len(cfg.get("hosts", [])),
"warnings": warnings,
"production_safe": len(warnings) == 0,
}
def main():
# Case 1: Historical RockMongo feature scope & legacy PHP 5 / php_mongo compatibility audit
legacy_cfg = {
"license": "New BSD License",
"php_major": 8,
"extension": "php_mongo",
"hosts": [{"host": "127.0.0.1", "port": 27017}, {"host": "10.0.0.12", "port": 27017}],
"admins": {"admin": "admin"},
"capabilities": ["server_status", "database_crud", "collection_index_ops", "gridfs_chunks"],
}
audit = audit_rockmongo_config(legacy_cfg)
c1_actual = {
"license": legacy_cfg["license"],
"capability_count": len(legacy_cfg["capabilities"]),
"audit": audit,
}
c1_expected = {
"license": "New BSD License",
"capability_count": 4,
"audit": {
"host_count": 2,
"warnings": [
"incompatible_with_php7_plus_removed_php_mongo_ext",
"insecure_default_admin_credentials",
],
"production_safe": False,
},
}
# Case 2: Modern MongoDB GUI/CLI replacement matrix (Compass, mongosh, Atlas UI)
modern_tools = {
"MongoDB Compass": {"official": True, "gui": True, "supports_modern_mongodb": True, "gridfs_and_explain": True},
"mongosh": {"official": True, "gui": False, "supports_modern_mongodb": True, "gridfs_and_explain": True},
"RockMongo": {"official": False, "gui": True, "supports_modern_mongodb": False, "gridfs_and_explain": False},
}
recommended = sorted(name for name, meta in modern_tools.items() if meta["supports_modern_mongodb"])
c2_actual = {
"recommended_modern_tools": recommended,
"rockmongo_deprecated": not modern_tools["RockMongo"]["supports_modern_mongodb"],
}
c2_expected = {
"recommended_modern_tools": ["MongoDB Compass", "mongosh"],
"rockmongo_deprecated": True,
}
cases = [
{
"name": "rockmongo_legacy_config_and_security_audit",
"summary": "Verify RockMongo's historical PHP 5 / php_mongo dependency, multi-host feature set, and default credential risk.",
"expected": c1_expected,
"actual": c1_actual,
"passed": c1_actual == c1_expected,
},
{
"name": "modern_mongodb_compass_migration_matrix",
"summary": "Verify modern official replacements (MongoDB Compass and mongosh) supersede unmaintained RockMongo.",
"expected": c2_expected,
"actual": c2_actual,
"passed": c2_actual == c2_expected,
},
]
print(json.dumps({"version": VERSION, "cases": cases}, ensure_ascii=False, indent=2))
if __name__ == "__main__":
main()
本例需在 Windows x64、CPython 3.12.14 离线文档/管道/索引/GridFS/ObjectId 验证环境(本地未安装 mongod/mongosh 服务端)。 中运行,请复制源码、保存文件或下载工程包后在本地执行验证。
运行说明与环境独立工程
运行环境:Windows x64、CPython 3.12.14 离线文档/管道/索引/GridFS/ObjectId 验证环境(本地未安装 mongod/mongosh 服务端)。
入口文件:projects/mongodb-working-with-rockmongo-lab/explore-working-with-rockmongo.py
本地运行步骤快速上手
- 点击上方“保存源码”保存为
explore-working-with-rockmongo.py,或下载右侧课程工程包。 - 确认本地已准备 Windows x64、CPython 3.12.14 离线文档/管道/索引/GridFS/ObjectId 验证环境(本地未安装 mongod/mongosh 服务端)。。
- 按对应章节命令执行,结合正文核对实际输出。
附件与关联工程包下载
课程关联工程包(登记关联49章) · 含当前章节或实例 · mbskycom202612a1732.zip
课程关联工程包(登记关联1章) · 含当前章节或实例 · mbskycom202612a1777.zip