How to find names of all collections using PyMongo?

后端 未结 5 1802
遇见更好的自我
遇见更好的自我 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 01:08

    To find the collections, you can use collection_names() - http://api.mongodb.org/python/current/api/pymongo/database.html#pymongo.database.Database.collection_names

    Edit:

    The collection_names is deprecated from 3.7 onwards and been replaced by list_collection_names - https://api.mongodb.com/python/current/api/pymongo/database.html#pymongo.database.Database.list_collection_names

提交回复
热议问题