MongoDB 命令行管理工具
Project description
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
依赖
- Python >= 3.9
- pymongo >= 4.0
- happy-python
License
MIT
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
zcx-1.0.1.tar.gz
(7.7 kB
view details)
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
zcx-1.0.1-py3-none-any.whl
(10.3 kB
view details)
File details
Details for the file zcx-1.0.1.tar.gz.
File metadata
- Download URL: zcx-1.0.1.tar.gz
- Upload date:
- Size: 7.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.14.5
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
74ea4eb98509b0338c7fffa99fefc0d6dd9230c21b693fbb070f257b917e27c3
|
|
| MD5 |
8d126fdb66ee0b3d3cac892813cb2bfb
|
|
| BLAKE2b-256 |
ae4c2907711c5831e6b1439697ad945f8fe342f0e6cbdae0494da29fac3d18d0
|
File details
Details for the file zcx-1.0.1-py3-none-any.whl.
File metadata
- Download URL: zcx-1.0.1-py3-none-any.whl
- Upload date:
- Size: 10.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.14.5
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
7be481a6f3ff6388b7d64287222fe30e4ddca9e26b34317ff8d5ea7bcecf8c1a
|
|
| MD5 |
56d0a72bfd8a01c7c45095d947f0a873
|
|
| BLAKE2b-256 |
77dd4820ad7dbabf3956fef69070eedf3206c3f2aaf3e1a59bac92dbf7ef2f88
|