How to find names of all collections using PyMongo?

后端 未结 5 1754
遇见更好的自我
遇见更好的自我 2021-02-01 00:08

How to find names of all collections using PyMongo and find all fields in chosen collection ? I have name of database and name of chosen collection. (Scenario : user input name

5条回答
  •  孤独总比滥情好
    2021-02-01 00:49

    I always used this way to get all collection names from my MongoDB database.

    import pymongo
    db_connect = pymongo.MongoClient('192.168.4.202', 20020)
    database_name = 'MY_DATABASE_NAME'
    database = db_connect[database_name]
    collection = database.collection_names(include_system_collections=False)
    for collect in collection:
        print collect
    

提交回复
热议问题