MongoDB 导出表结构

MongoStructure.py

Scan MongoDB Collection Structure

GitHub https://github.com/XiaoGerGer/MongoStructure.py

Usage

$ python MongoStructure.py --help
usage: MongoStructure.py [-h] [-v] [-p PORT] [-o {tree,path}]
                         host database collection

Scan MongoDB Collection Structure

positional arguments:
  host                  mongoDB Server host
  database              mongoDB Database name
  collection            mongoDB Collection name

optional arguments:
  -h, --help            show this help message and exit
  -v, --version         show program's version number and exit
  -p PORT, --port PORT  mongoDB Server host
  -o {tree,path}, --out_type {tree,path}
                        default is value: tree

Exsample

db.getCollection('Human').find({})

/* 1 */
{
    "_id" : ObjectId("5c27107a29c1889ae83291f6"),
    "tag" : "student",
    "birthday" : ISODate("2017-08-04T06:38:11.480Z"),
    "girlfriend" : {
        "name" : "mari",
        "age" : 21.0
    },
    "scores" : {
        "math" : 98.0,
        "chemical" : 95.0
    }
}

/* 2 */
{
    "_id" : ObjectId("5c27118829c1889ae83291f7"),
    "tag" : "python-man",
    "birthday" : null,
    "girlfriend" : null,
    "salary" : {
        "work" : "¥5000/month",
        "other" : "¥5/year"
    }
}
$ python MongoStructure.py  10.188.188.22 test Human
Collection Structure: 100%|████████████████| 2/2 [00:00<00:00, 814.98it/s]
Done!
========== test.Human ==========
|____ _id : bson.objectid.ObjectId
|____ birthday : NoneType, datetime.datetime
|____ girlfriend : NoneType, dict
|   |____ age : float
|   |____ name : str
|____ salary : dict
|   |____ other : str
|   |____ work : str
|____ scores : dict
|   |____ chemical : float
|   |____ math : float
|____ tag : str
========== test.Human ==========

$ python MongoStructure.py  10.188.188.22 test Human -o path
Collection Structure: 100%|████████████████| 2/2 [00:00<00:00, 814.98it/s]
Done!
========== test.Human ==========
_id
birthday
girlfriend
girlfriend.age
girlfriend.name
salary
salary.other
salary.work
scores
scores.chemical
scores.math
tag
========== test.Human ==========

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • 关于Mongodb的全面总结 MongoDB的内部构造《MongoDB The Definitive Guide》...
    中v中阅读 32,077评论 2 89
  • # Awesome Python [![Awesome](https://cdn.rawgit.com/sindr...
    emily_007阅读 2,242评论 0 3
  • afinalAfinal是一个android的ioc,orm框架 https://github.com/yangf...
    passiontim阅读 15,609评论 2 45
  • 我们今天一天都在游览三峡,上午主要是去看三峡的发电结构,下午我们则乘游轮游览了三峡,观赏沿路的美景,我们并亲眼见证...
    lkl88888阅读 210评论 0 1
  • “双抢”过后,全县的各个生产队的公粮收购与上缴工作紧锣密鼓地进行着,上级给了城山大队派一名征购员的指标。老队长胡忠...
    影音纪事阅读 633评论 0 0