Skip to content
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

MOTOR-784 Versioned API migration example for ecosystem docs #127

Conversation

prashantmital
Copy link
Contributor

@prashantmital prashantmital commented Jul 22, 2021

This is a weird one. Somehow we are supposed to show the output of running some commands as part of the example. I am not really sure how to do that...

"raise an exception")

# Start Versioned API Example 6
# pymongo.errors.OperationFailure: Provided apiStrict:true, but the command count is not in API Version 1, full error: {'ok': 0.0, 'errmsg': 'Provided apiStrict:true, but the command count is not in API Version 1', 'code': 323, 'codeName': 'APIStrictError', '$clusterTime': {'clusterTime': Timestamp(1626977595, 10), 'signature': {'hash': b'\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00', 'keyId': 0}}, 'operationTime': Timestamp(1626977595, 10)}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this makes sense.


# Start Versioned API Example 7
await client.db.sales.aggregate(
[{"$group": {"_id": None, "count": {"$count": {}}}}]).to_list(length=None)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should really be using count_documents() or estimated_document_count() instead of aggregate . I asked about it on the drivers ticket https://jira.mongodb.org/browse/DRIVERS-1846

{"_id": 5, "item": "xyz", "price": 5, "quantity": 10, "date": datetime.datetime.strptime("2021-02-15T09:05:00Z", "%Y-%m-%dT%H:%M:%SZ")},
{"_id": 6, "item": "xyz", "price": 5, "quantity": 5, "date": datetime.datetime.strptime("2021-02-15T12:05:10Z", "%Y-%m-%dT%H:%M:%SZ")},
{"_id": 7, "item": "xyz", "price": 5, "quantity": 10, "date": datetime.datetime.strptime("2021-02-15T14:12:12Z", "%Y-%m-%dT%H:%M:%SZ")},
{"_id": 8, "item": "abc", "price": 10, "quantity": 5, "date": datetime.datetime.strptime("2021-03-16T20:20:13Z", "%Y-%m-%dT%H:%M:%SZ")}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggest refactoring to make this less verbose. Maybe:

def strptime(s):
    return datetime.datetime.strptime(s, "%Y-%m-%dT%H:%M:%SZ")
...
await client.db.sales.insert_many([
            {"_id": 1, "item": "abc", "price": 10, "quantity": 2, "date": strptime("2021-01-01T08:00:00Z")},
    

Copy link
Member

@ShaneHarvey ShaneHarvey left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we should wait until the countDocuments idea is clarified in DRIVERS-1846 before merging this. We don't need to hold up 2.5 for this change.

@prashantmital
Copy link
Contributor Author

@ShaneHarvey discussion on the DRIVERS ticket seems to have wrapped up. I've updated this PR to reflect the new example.

@prashantmital prashantmital merged commit 2a37056 into mongodb:master Jul 22, 2021
@prashantmital prashantmital deleted the MOTOR-784/versioned-api-migration-example branch July 22, 2021 22:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants