如何从 python 使用 Heroku 的 mongolab 插件?
该文档仅讨论如何从 ruby 执行此操作。
The documentation only talks about how to do it from ruby.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
该文档仅讨论如何从 ruby 执行此操作。
The documentation only talks about how to do it from ruby.
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
接受
或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
发布评论
评论(5)
我是来自 MongoLab 的 Will。我们有一个关于如何使用官方 python 驱动程序 (pymongo) 在 Python 中进行连接的通用示例。这个示例并不是从 Heroku 进行连接,但应该是类似的。不同之处在于,您需要从 Heroku ENV 环境中提取驱动程序配置以提供给驱动程序。
https://github.com/mongolab/mongodb-driver -examples/blob/master/python/pymongo_simple_example.py
如果您仍然遇到问题,请随时直接联系我们 [电子邮件受保护]
-will
This is Will from MongoLab. We have a generic example of how to connect in Python using the official python driver (pymongo). This example is not for connecting from Heroku per say but it should be similar. The difference is that you will need to pluck your driver config from your Heroku ENV environment to supply to the driver.
https://github.com/mongolab/mongodb-driver-examples/blob/master/python/pymongo_simple_example.py
If you still have trouble feel free to contact us directly at [email protected]
-will
我正在使用以下内容:
I'm using the following:
将插件安装到 Heroku 应用后,通过在命令行上运行
heroku config
来获取连接字符串设置。将有一个带有 MONGOLAB_URI 键的条目,其形式如下:
MONGOLAB_URI => mongodb://user:[电子邮件受保护]:27707/db
只是来自的信息python 中的 uri 通过从 uri 字符串创建连接。
Get the connection string settings by running
heroku config
on the command line after installed the add-on to your heroku app.There will be an entry with the key MONGOLAB_URI in this form:
MONGOLAB_URI => mongodb://user:[email protected]:27707/db
Simply the info from the uri in python by creating a connection from the uri string.
我认为这样的事情应该有效:
I think something like this should work:
PyMongo 现在提供了一个 get_default_database() 方法,使整个练习变得简单:
PyMongo now provides a
get_default_database()
method that makes this entire exercise trivial: