Skip to content

Commit 41b3d2e

Browse files
authored
Add flags to enable strict stable API (#8)
1 parent 95f073c commit 41b3d2e

2 files changed

Lines changed: 16 additions & 3 deletions

File tree

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,5 @@ How to run:
77
```sh
88
python3 pymongo_test.py "mongodb://username:password@localhost:27017/?authMechanism=PLAIN"
99
```
10+
11+
To use the strict Stable API run with `--strict` flag.

pymongo_test.py

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,20 @@
11
from pymongo import MongoClient
2-
import sys
2+
from pymongo.server_api import ServerApi
3+
import argparse
34

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

6-
client = MongoClient(uri)
10+
parser.add_argument('uri') # positional argument
11+
parser.add_argument('-s', '--strict', action='store_true', help='Use strict stable API mode.')
12+
13+
if parser.parse_args().strict:
14+
server_api = ServerApi('1', strict=True)
15+
client = MongoClient(parser.parse_args().uri, server_api=server_api)
16+
else:
17+
client = MongoClient(parser.parse_args().uri)
718

819
db = client.test
920
res = db.command('ping', '1')

0 commit comments

Comments
 (0)