如何使用python cloudant调用带有键列表的_all_docs主索引?
我目前正在使用主索引查询Cloudant数据库中的键列表:如何使用python cloudant调用带有键列表的_all_docs主索引?,python,cloudant,python-cloudant,Python,Cloudant,Python Cloudant,我目前正在使用主索引查询Cloudant数据库中的键列表: class DAO: @staticmethod def get_movie_names(movie_ids: List[int]) -> Dict[int, str]: # The movie_ids in cloudant are stored as strings so convert to # correct format for querying mo
class DAO:
@staticmethod
def get_movie_names(movie_ids: List[int]) -> Dict[int, str]:
# The movie_ids in cloudant are stored as strings so convert to
# correct format for querying
movie_ids = [ str(id) for id in movie_ids ]
keys = urllib.parse.quote_plus(json.dumps(movie_ids))
# The movie id is stored in the _id field, so we query it
# using the 'keys' parameter
end_point = '{0}/{1}/_all_docs?keys={2}&include_docs=true'.format (
CL_URL, CL_MOVIEDB, keys
)
response = cloudant_client.r_session.get(end_point)
movie_data = json.loads(response.text)
movie_names = {}
if 'rows' in movie_data:
for row in movie_data['rows']:
if 'doc' in row:
movie_id = int(row['key'])
movie_name = row['doc']['name']
movie_names[movie_id] = movie_name
return movie_names
似乎我可以通过使用来实现这一点。如果我正确理解了文档,这将返回所有文档,然后您可以过滤返回的结果。但是,我希望通过向Cloudant请求传递参数进行过滤,以便只返回我感兴趣的数据。这可能吗?克里斯-
CloudantDatabase
允许您访问所有文档,这就是您想要的吗
Chris-CloudantDatabase
允许您访问所有文档
,这就是您想要的吗
还有CouchDatabase/CloudantDatabase对象提供的自定义\u结果上下文管理器,它具有将调用包装为所有\u文档的额外好处。还有CouchDatabase/CloudantDatabase对象提供的自定义\u结果上下文管理器,它具有将调用包装为所有\u文档的额外好处结果。