Skip to main content

zcx — MongoDB 命令行管理工具

通过简单的命令行操作管理 MongoDB 集合,支持增删查改、数据导入导出。

安装

pip install zcx

快速开始

首次运行任意 zcx 命令时,会自动在 ~/.zcx/ 目录下生成配置文件:

~/.zcx/
├── config.ini   # 数据库连接配置(需要手动编辑)
└── log.ini      # 日志配置(自动生成,无需修改)

编辑 ~/.zcx/config.ini,填写你的 MongoDB 连接信息:

[main]
db_url = mongodb://127.0.0.1:27017/
db_name = mydatabase
collection_name = mycollection

使用说明

用法: zcx [-c <配置文件>] [-l <日志配置文件>] [-i <数据>] [-d <条件>]
          [-s [条件]] [-u <数据>] [--dump <文件名>] [--import <文件名>]

选项:
  -h, --help       显示此帮助信息并退出
  -c 配置文件       配置文件路径,默认为 ~/.zcx/config.ini
  -l 日志配置文件   日志配置文件路径,默认为 ~/.zcx/log.ini
  -i 数据          执行插入操作,提供数据(JSON 格式)
  -d 条件          执行删除操作,提供查询条件(JSON 格式)
  -s [条件]        执行查询操作,提供查询条件(JSON 格式),不填条件则查全部
  -u 数据          执行更新操作,提供查询条件和更新数据(JSON 格式)
  --dump 文件名     导出集合数据到指定文件(JSON 格式)
  --import 文件名   从指定文件导入数据到集合(JSON 格式)

示例

插入数据

zcx -i '{"name": "Alice", "age": 25, "city": "Beijing"}'

查询数据

# 查询全部
zcx -s

# 按条件查询
zcx -s '{"name": "Alice"}'

更新数据

以 name 字段作为匹配条件,更新该记录的其他字段:

zcx -u '{"name": "Alice", "age": 26, "city": "Shanghai"}'

删除数据

zcx -d '{"name": "Alice"}'

导出数据

将集合中所有数据导出为 JSON 文件:

zcx --dump backup.json

导入数据

从 JSON 文件批量导入数据(重复键自动跳过):

zcx --import backup.json

使用自定义配置文件

zcx -c /path/to/config.ini -s

依赖

License

MIT

Metadata

Release files for zcx 1.0.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for zcx 1.0.1
File Size Uploaded
zcx-1.0.1.tar.gz 7.7 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for zcx 1.0.1
File Interpreter ABI Platform
zcx-1.0.1-py3-none-any.whl Python 3 none any Details

Total release size: 18.0 kB

Release files / zcx-1.0.1.tar.gz

Download URL zcx-1.0.1.tar.gz
Size 7.7 kB
Tags Source
SHA-256 checksum
How to use checksums
74ea4eb98509b0338c7fffa99fefc0d6dd9230c21b693fbb070f257b917e27c3
BLAKE2b-256 checksum
How to use checksums
ae4c2907711c5831e6b1439697ad945f8fe342f0e6cbdae0494da29fac3d18d0
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.14.5

Release files / zcx-1.0.1-py3-none-any.whl

Download URL zcx-1.0.1-py3-none-any.whl
Size 10.3 kB
Tags Python 3
SHA-256 checksum
How to use checksums
7be481a6f3ff6388b7d64287222fe30e4ddca9e26b34317ff8d5ea7bcecf8c1a
BLAKE2b-256 checksum
How to use checksums
77dd4820ad7dbabf3956fef69070eedf3206c3f2aaf3e1a59bac92dbf7ef2f88
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.14.5

Release history Release notifications | RSS feed

This release

1.0.1 This release

2 release files

1.0.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page