使用 python 查询 cloudant
对此可能有一个明显的答案,但我似乎无法在任何地方找到它:查询存储在 cloudant 服务器上的 couchdb 数据库的最佳方法是什么?我尝试使用临时视图,按照 couchdb.py 说明:
>>> db['johndoe'] = dict(type='Person', name='John Doe')
>>> db['maryjane'] = dict(type='Person', name='Mary Jane')
>>> db['gotham'] = dict(type='City', name='Gotham City')
>>> map_fun = '''function(doc) {
... if (doc.type == 'Person')
... emit(doc.name, null);
... }'''
>>> for row in db.query(map_fun):
... print row.key
John Doe
Mary Jane
虽然这适用于本地托管数据库,但使用 CloudAnt 时它会返回错误:
couchdb.http.ServerError: (403, ('forbidden', 'temp views are disabled on Cloudant'))
我已阅读有关查询的 cloudant 教程,但建议的查询语法似乎很笨拙,而且不清楚如何实现将其应用到Python中!有一个简单的方法可以解决这个问题吗?
There may be an obvious answer to this, but I can't seem to find it anywhere: what's the best way to query couchdb databases stored on cloudant servers? I try using temporary views, a la the couchdb.py instructions:
>>> db['johndoe'] = dict(type='Person', name='John Doe')
>>> db['maryjane'] = dict(type='Person', name='Mary Jane')
>>> db['gotham'] = dict(type='City', name='Gotham City')
>>> map_fun = '''function(doc) {
... if (doc.type == 'Person')
... emit(doc.name, null);
... }'''
>>> for row in db.query(map_fun):
... print row.key
John Doe
Mary Jane
While this works on locally hosted databases, with CloudAnt it returns the error:
couchdb.http.ServerError: (403, ('forbidden', 'temp views are disabled on Cloudant'))
I've read the cloudant tutorial on querying but the querying syntax proposed seems clumsy and it's not obvious how to work it into python! Is there an easy way around this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
这就是我用 python 添加记录的方式。
这就是我在Python中查询10条记录的方法。
This is how I am adding a record with python.
This is how i query 10 records in Python.
Cloudant 禁止临时视图的原因是它们无法扩展。您将需要创建一个包含已定义视图的设计文档。以下是设计文档及其上定义的视图的链接:
http://max.ic.ht/_utils/document.html?action/_design/action
我不确定如何在 couchdb.py 中执行此操作,但您可能想尝试不同的 python 库。 中创建视图的部分的链接
这是有关在 couchquery http://mikeal.github.com/ couchquery/#creating-views
The reason Cloudant forbids temp views is because they do not scale. You will need to create a design document with defined views in it. Here is a link to what a design document is like with views defined on it:
http://max.ic.ht/_utils/document.html?action/_design/action
I am not sure about how to do it in couchdb.py, but you might want to try a different python library. Here is a link to the section about creating views in couchquery
http://mikeal.github.com/couchquery/#creating-views
只是注意到 Cloudant 现在有一个官方的 python 库, https://github.com/cloudant/python-cloudant 。
Just noting that Cloudant now has an official python library, https://github.com/cloudant/python-cloudant.
您可能应该使用 couchdbkit。它使设置视图变得容易。我认为您不能再在 Cloudant 中使用临时视图。
You should probably use couchdbkit. It makes setting up views easy. I don't think you can use temporary views in Cloudant anymore.