Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Python Mogo ImportError: cannot import name Connection

Tags:

python

mongodb

Can't figure out why this is not working.

mogo==0.2.4

File "/Users/Sam/Envs/AdiosScraper/lib/python2.7/site-packages/mogo/connection.py", line 3, in <module>
    from pymongo import Connection as PyConnection
ImportError: cannot import name Connection
like image 882
888 Avatar asked Apr 17 '15 05:04

888


4 Answers

Under PyMongo 3.2, you can connect to MongoDB like this:

from pymongo import MongoClient
c = MongoClient()

mongo_client – Tools for connecting to MongoDB

like image 175
林叶辉 Avatar answered Nov 19 '22 15:11

林叶辉


i had same problem and too many files had the import, so, i couldn't risk changing the import - (didn't knew exactly where all it is mentioned).

I just downgraded pymongo:

sudo pip install pymongo==2.7.2

and it worked!

like image 43
NoobEditor Avatar answered Nov 19 '22 17:11

NoobEditor


Mogo Connection

from mogo import connect as PyConnection

pymongo.Connection is deprecated use MongoClient instead. In terms of use they are very similar.

like image 5
thegreenogre Avatar answered Nov 19 '22 16:11

thegreenogre


In addition to https://stackoverflow.com/a/34766754/1587329, here's the API message (deprecated at 2.6.3, removed at 3.0):

Warning: DEPRECATED: Connection is deprecated. Please use MongoClient instead.

like image 1
serv-inc Avatar answered Nov 19 '22 17:11

serv-inc