Skip to content
This repository was archived by the owner on Aug 30, 2024. It is now read-only.

Commit e4a0224

Browse files
authored
Added get_query_result example to getting started (#423)
Added get_query_result example to getting started
1 parent 78ea0c4 commit e4a0224

File tree

3 files changed

+25
-0
lines changed

3 files changed

+25
-0
lines changed

CHANGES.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
# Unreleased
2+
3+
- [IMPROVED] Updated `Getting started` section with a `get_query_result` example.
4+
15
# 2.11.0 (2019-01-21)
26

37
- [NEW] Added option for client to authenticate with IAM token server.

docs/getting_started.rst

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -372,6 +372,26 @@ object already exists.
372372
for result in result_collection:
373373
print(result)
374374
375+
This example retrieves the query result from the specified database based on the query parameters provided, updates the
376+
document, and saves the document in the remote database.
377+
By default, the result is returned as a ``QueryResult`` which uses the skip and limit query parameters internally to
378+
handle slicing and iteration through the query result collection. For more detail on slicing and iteration, refer
379+
to the :class:`~cloudant.result.QueryResult` documentation.
380+
381+
.. code-block:: python
382+
383+
# Retrieve documents where the name field is 'foo'
384+
selector = {'name': {'$eq': 'foo'}}
385+
docs = my_database.get_query_result(selector)
386+
for doc in docs:
387+
# Create Document object from dict
388+
updated_doc = Document(my_database, doc['_id'])
389+
updated_doc.update(doc)
390+
# Update document field
391+
updated_doc['name'] = 'new_name'
392+
# Save document
393+
updated_doc.save()
394+
375395
****************
376396
Context managers
377397
****************

test-requirements.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
mock==1.3.0
22
nose
33
sphinx
4+
sphinx_rtd_theme
45
pylint
56
flaky

0 commit comments

Comments
 (0)