-
Notifications
You must be signed in to change notification settings - Fork 19
DOCSP-48163: Add async examples for Read pages #227
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
✅ Deploy Preview for docs-pymongo ready!
To edit notification comments on pull requests, go to your Netlify site configuration. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM with small things
# start-tailable-cursor-async | ||
oplog = client.local.oplog.rs | ||
first = oplog.find().sort('$natural', pymongo.ASCENDING).limit(-1).next() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
first = oplog.find().sort('$natural', pymongo.ASCENDING).limit(-1).next() | |
first = await oplog.find().sort('$natural', pymongo.ASCENDING).limit(-1).next() |
cursor = oplog.find({'ts': {'$gt': ts}}, | ||
cursor_type=pymongo.CursorType.TAILABLE_AWAIT) | ||
await while async cursor.alive: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
await while async cursor.alive: | |
while cursor.alive: |
# You end up here if the find() method returns no documents, or if | ||
# no new documents are added to the collection for more than 1 second. | ||
time.sleep(1) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
time.sleep(1) | |
await asyncio.sleep(1) |
# start-distinct | ||
results = await restaurants.distinct("borough") | ||
|
||
async for restaurant in results: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
async for restaurant in results: | |
for restaurant in results: |
distinct()
returns a list.
"cuisine": "Italian" | ||
}) | ||
|
||
async for restaurant in results: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
async for restaurant in results: | |
for restaurant in results: |
print(count) | ||
# end-estimated-count | ||
# start-distinct | ||
results = collection.distinct("<field name>") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
results = collection.distinct("<field name>") | |
results = await collection.distinct("<field name>") |
# start-distinct | ||
results = collection.distinct("<field name>") | ||
|
||
async for document in results: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
async for document in results: | |
for document in results: |
|
||
# end example code here | ||
|
||
client.close() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
client.close() | |
await client.close() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Realize I forgot to wrap this in an async function (Python complains otherwise) so I can also do that
Pull Request Info
PR Reviewing Guidelines
JIRA - https://jira.mongodb.org/browse/DOCSP-48163
Staging Links
Self-Review Checklist