简体   繁体   中英

How can I get a list of collections in a database using MongoEngine?

I'd like to know what call I can make from a python MongoEngine instance to get a list of collection names from my mongodb database? If I were using pymongo directly I could call db.list_collection_names() , but I can't find a similar call from MongoEngine. Specifically I'm using flask-mongoengine if that matters.

MongoEngine

from mongoengine import connect

db_name = 'test'
connection = connect(db_name)
connection.get_database(db_name).list_collection_names()

Flask-MongoEngine

from flask import Flask
from flask_mongoengine import MongoEngine

app = Flask(__name__)
db = MongoEngine(app)
#app.config.from_pyfile('the-config.cfg')
#app.config['MONGODB_SETTINGS'] = {}
db.get_db().list_collection_names()

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM