如何使用 python-cloudant 调用带有键列表的 _all_docs 主索引?

how to call _all_docs primary index with list of keys using 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
        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.result.Result 来实现这一点。如果我对文档的理解正确,这将 return 所有文档,然后您可以过滤 returned 结果。但是,我想通过将参数传递给 Cloudant 请求来进行过滤,以便我只 return 我感兴趣的数据。这可能吗?

Chris - CloudantDatabase 允许您访问 all_docs,这是您想要的吗?

http://python-cloudant.readthedocs.io/en/latest/database.html#cloudant.database.CouchDatabase.all_docs