Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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