简体   繁体   中英

How to pick a specific connection with mongokit?

I'm trying to connect to a Mongo DB with Django and Mongokit (using django-mongokit). When I try to feed it a remote

In settings.py:

DATABASES = {
    'default': dj_database_url.config(default=os.environ['DATABASE_URL']),
    'mongodb': dj_database_url.parse(os.environ['MONGOHQ_URL']),
}

DATABASES is correctly populated with connection data, for what it's worth.

In the main routine:

from mongokit import Connection

# ...
conn = Connection('mongodb')
conn.register([Account])
db = conn.foo
collection = db.bar

This throws a getaddrinfo failed error. Connection(), it seems, wants a PymongoConnection, but I'm not sure how to get that. And when I try feeding a remote URL into DATABASES.mongodb, it freaks out as well. Any ideas?

Edit: Not really a solution, but I ended up just using pymongo straight rather than django-mongokit. Oh well.

conn = Connection('mongodb')试图连接到一个名叫mongodb -使用conn = Connection(DATABASES['mongodb'])可以通过您设置的任何方式(通过app.config ?)进行操作成为做到这一点的方式。

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