@@ -57,10 +57,10 @@ except ApiException as ae:
5757# 3. Create a document ================================================
5858# Create a document object with "example" id
5959example_doc_id = " example"
60- # Setting `id ` for the document is optional when "post_document"
61- # function is used for CREATE. When `id ` is not provided the server
60+ # Setting `_id ` for the document is optional when "post_document"
61+ # function is used for CREATE. When `_id ` is not provided the server
6262# will generate one for your document.
63- example_document: Document = Document(id = example_doc_id)
63+ example_document: Document = Document(_id = example_doc_id)
6464
6565# Add "name" and "joined" fields to the document
6666example_document.name = " Bob Smith"
@@ -84,22 +84,19 @@ create_document_response = client.put_document(
8484"""
8585# =====================================================================
8686
87- # Keeping track of the revision number of the document object
88- # is necessary for further UPDATE/DELETE operations:
89- example_document.rev = create_document_response[" rev" ]
90- print (f ' You have created the document: \n { example_document} ' )
87+ response_body = json.dumps(create_document_response, indent = 2 )
88+ print (f ' You have created the document. Response body: \n { response_body} ' )
9189```
9290
9391When you run the code, you see a result similar to the following output.
9492
9593``` text
9694"orders" database created.
97- You have created the document:
95+ You have created the document. Response body :
9896{
99- "_id": "example",
100- "_rev": "1-1b403633540686aa32d013fda9041a5d",
101- "name": "Bob Smith",
102- "joined": "2019-01-24T10:42:99.000Z"
97+ "ok": true,
98+ "id": "example",
99+ "rev": "1-1b403633540686aa32d013fda9041a5d"
103100}
104101```
105102
@@ -155,14 +152,14 @@ print(f'Document retrieved from database:\n'
155152When you run the code, you see a result similar to the following output.
156153
157154``` text
158- Server Version: 2.1 .1
155+ Server Version: 3.2 .1
159156Document count in "orders" database is 1.
160157Document retrieved from database:
161158{
162159 "_id": "example",
163160 "_rev": "1-1b403633540686aa32d013fda9041a5d",
164161 "name": "Bob Smith",
165- "joined": "2019-01-24T10:42:99 .000Z"
162+ "joined": "2019-01-24T10:42:59 .000Z"
166163}
167164```
168165
253250
254251except ApiException as ae:
255252 if ae.status_code == 404 :
256- print (' Cannot delete document because either ' +
253+ print (' Cannot update document because either ' +
257254 f ' " { example_db_name} " database or " { example_doc_id} " ' +
258255 ' document was not found.' )
259256```
@@ -262,6 +259,7 @@ except ApiException as ae:
262259When you run the code, you see a result similar to the following output.
263260
264261``` text
262+ You have updated the document:
265263{
266264 "_id": "example",
267265 "_rev": "2-4e2178e85cffb32d38ba4e451f6ca376",
311309except ApiException as ae:
312310 if ae.status_code == 404 :
313311 print (' Cannot delete document because either ' +
314- f ' " { example_db_name} " database or " { example_doc_id} " ' +
312+ f ' " { example_db_name} " database or " { example_doc_id} " ' +
315313 ' document was not found.' )
316314```
317315
0 commit comments