Skip to content

Commit

Permalink
Add flags to enable strict stable API (#8)
Browse files Browse the repository at this point in the history
  • Loading branch information
b1ron authored Apr 16, 2024
1 parent 95f073c commit 41b3d2e
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 3 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,5 @@ How to run:
```sh
python3 pymongo_test.py "mongodb://username:password@localhost:27017/?authMechanism=PLAIN"
```

To use the strict Stable API run with `--strict` flag.
17 changes: 14 additions & 3 deletions pymongo_test.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,20 @@
from pymongo import MongoClient
import sys
from pymongo.server_api import ServerApi
import argparse

uri = sys.argv[-1]
parser = argparse.ArgumentParser(
prog='python-example',
description='A simple example of using MongoDB with PyMongo',
add_help=True)

client = MongoClient(uri)
parser.add_argument('uri') # positional argument
parser.add_argument('-s', '--strict', action='store_true', help='Use strict stable API mode.')

if parser.parse_args().strict:
server_api = ServerApi('1', strict=True)
client = MongoClient(parser.parse_args().uri, server_api=server_api)
else:
client = MongoClient(parser.parse_args().uri)

db = client.test
res = db.command('ping', '1')
Expand Down

0 comments on commit 41b3d2e

Please sign in to comment.