Skip to content

Commit 851ab6c

Browse files
committed
NS feedback
1 parent eab280f commit 851ab6c

File tree

4 files changed

+22
-18
lines changed

4 files changed

+22
-18
lines changed

source/includes/cursors/tailable-cursor.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,19 +19,19 @@
1919

2020
# start-tailable-cursor-async
2121
oplog = client.local.oplog.rs
22-
first = oplog.find().sort('$natural', pymongo.ASCENDING).limit(-1).next()
22+
first = await oplog.find().sort('$natural', pymongo.ASCENDING).limit(-1).next()
2323
print(first)
2424
ts = first['ts']
2525

2626
while True:
2727
cursor = oplog.find({'ts': {'$gt': ts}},
2828
cursor_type=pymongo.CursorType.TAILABLE_AWAIT)
29-
await while async cursor.alive:
29+
while cursor.alive:
3030
async for doc in cursor:
3131
ts = doc['ts']
3232
print(doc)
3333

3434
# You end up here if the find() method returns no documents, or if
3535
# no new documents are added to the collection for more than 1 second.
36-
time.sleep(1)
36+
await asyncio.sleep(1)
3737
# end-tailable-cursor-async

source/includes/read/distinct-async.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# start-distinct
22
results = await restaurants.distinct("borough")
33

4-
async for restaurant in results:
4+
for restaurant in results:
55
print(restaurant)
66
# end-distinct
77

@@ -10,7 +10,7 @@
1010
"cuisine": "Italian"
1111
})
1212

13-
async for restaurant in results:
13+
for restaurant in results:
1414
print(restaurant)
1515
# end-distinct-with-query
1616

source/includes/usage-examples/retrieve-code-examples-async.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,9 @@
2626
print(count)
2727
# end-estimated-count
2828
# start-distinct
29-
results = collection.distinct("<field name>")
29+
results = await collection.distinct("<field name>")
3030

31-
async for document in results:
31+
for document in results:
3232
print(document)
3333
# end-distinct
3434

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,23 @@
1+
import asyncio
12
import pymongo
23
from pymongo import AsyncMongoClient
34

4-
try:
5-
uri = "<connection string URI>"
6-
client = AsyncMongoClient(uri)
5+
async def main():
6+
try:
7+
uri = "<connection string URI>"
8+
client = AsyncMongoClient(uri)
79

8-
database = client["<database name>"]
9-
collection = database["<collection name>"]
10+
database = client["<database name>"]
11+
collection = database["<collection name>"]
1012

11-
# start example code here
13+
# start example code here
1214

13-
# end example code here
15+
# end example code here
1416

15-
client.close()
17+
await client.close()
1618

17-
except Exception as e:
18-
raise Exception(
19-
"The following error occurred: ", e)
19+
except Exception as e:
20+
raise Exception(
21+
"The following error occurred: ", e)
22+
23+
asyncio.run(main())

0 commit comments

Comments
 (0)