<p>根据我的理解,我想您想知道如何使用Python执行类似SQL的查询来检索documentdbapi的azurecosmsdb上的文档,请参考下面来自<a href="https://docs.microsoft.com/en-us/azure/cosmos-db/create-documentdb-python#review-the-code" rel="nofollow noreferrer">here</a>的代码。在</p>
<blockquote>
<p>A query is performed using SQL</p>
<pre><code># Query them in SQL
query = { 'query': 'SELECT * FROM server s' }
options = {}
options['enableCrossPartitionQuery'] = True
options['maxItemCount'] = 2
result_iterable = client.QueryDocuments(collection['_self'], query, options)
results = list(result_iterable);
print(results)
</code></pre>
</blockquote>
<p>上面的代码正在使用方法<a href="http://azure.github.io/azure-documentdb-python/api/pydocumentdb.document_client.html#pydocumentdb.document_client.DocumentClient.QueryDocuments" rel="nofollow noreferrer">^{<cd1>}</a>。在</p>
<p>有任何问题,请随时告诉我。在</p>
<hr/>
<p>更新:结合我的示例代码为你链接的另一个SO线程,如下所示。在</p>
<pre><code>from pydocumentdb import document_client
uri = 'https://ronyazrak.documents.azure.com:443/'
key = '<your-primary-key>'
client = document_client.DocumentClient(uri, {'masterKey': key})
db_id = 'test1'
db_query = "select * from r where r.id = '{0}'".format(db_id)
db = list(client.QueryDatabases(db_query))[0]
db_link = db['_self']
coll_id = 'test1'
coll_query = "select * from r where r.id = '{0}'".format(coll_id)
coll = list(client.QueryCollections(db_link, coll_query))[0]
coll_link = coll['_self']
query = { 'query': 'SELECT * FROM server s' }
docs = client.QueryDocuments(coll_link, query)
print list(docs)
</code></pre>