How to find names of all collections using PyMongo?

后端 未结 5 937
北恋
北恋 2021-02-01 00:43

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:55

    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
    

提交回复
热议问题