如何使用 PyMongo 查找所有集合的名称? [英] How to find names of all collections using PyMongo?

查看:51
本文介绍了如何使用 PyMongo 查找所有集合的名称?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何使用 PyMongo 查找所有集合的名称并查找所选集合中的所有字段?我有数据库名称和所选集合的名称.(场景:用户输入数据库名称,需要查找所有集合并显示在下拉列表中,当用户单击一项时需要查找该集合中的所有字段)

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 of database, need to find all collections and show in dropdown list, when user click on one item need to find all fields in that collection)

推荐答案

要查找集合,可以使用 collection_names() - http://api.mongodb.org/python/current/api/pymongo/database.html#pymongo.database.Database.collection_names

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

collection_names3.7 开始被弃用,并被替换为 list_collection_names - https://api.mongodb.com/python/current/api/pymongo/database.html#pymongo.database.Database.list_collection_names

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

这篇关于如何使用 PyMongo 查找所有集合的名称?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆