4
from views import app
    mongo = PyMongo(app)
    print mongo.db.activity.count()

Since I'm trying to use Pymongo count()

and it raises

File "Z:\Activities\modules.py", line 9, in set_id
    mongo = PyMongo(app)
  File "D:\Python27\lib\site-packages\flask_pymongo\__init__.py", line 98, in __init__
    self.init_app(app, config_prefix)
  File "D:\Python27\lib\site-packages\flask_pymongo\__init__.py", line 122, in init_app
    raise Exception('duplicate config_prefix "%s"' % config_prefix)
Exception: duplicate config_prefix "MONGO"

But in fact I use default. What should I do?

Andrey Korneyev
  • 26,353
  • 15
  • 70
  • 71
Gladuo
  • 77
  • 9

1 Answers1

5

PyMongo has already been initialized for you and is ready to be consumed at app.data.driver.

Try with the following:

mongo = app.data.driver
print mongo.db.activity.count()
Nicola Iarocci
  • 6,606
  • 1
  • 20
  • 33
  • I'm seeing the same issue, except the above solution does not work: AttributeError: 'Flask' object has no attribute 'data' It's possible this is an incompatibility between Flask-PyMongo 0.4.0 and pymongo 3.2.. – cacois Jan 28 '16 at 04:38
  • @cacois it should work. I just tested it with v0.6.1 which is current stable. Where you are using it (I tested in a pre_GET callback function)? By the message you get I would guess that you are not using the Eve object. – Nicola Iarocci Jan 28 '16 at 06:36
  • Sorry, should have been more clear. No, not using Eve, (I'm using Flask) but I am seeing the same error and misunderstood your guidance. I was assuming this error was a PyMongo issue, but from your response I'm guessing its an issue with the PyMongo-Flask module. Thanks for the reply! – cacois Jan 29 '16 at 13:50