In the following example, the database application is configured to use a user, bgReadWrite. This database user has limited access to the database as it is assigned the readWrite built-in role. Further, this user is only able to use the biglittle database. In the example you see in the next line, we create a MongoClient instance assigned the bgReadWrite user:
import pprint
from pymongo import MongoClient
client = MongoClient(
'localhost',
username='bgReadWrite',
password='password',
authSource='biglittle',
authMechanism='SCRAM-SHA-256');
All the data is first removed from test_collection in the biglittle database and a single document is inserted. This demonstrates the ability of the application to write:
client.biglittle.test_collection.delete_many({})
insert_result = client.biglittle.test_collection.insert_one( {
'first_name' : 'Fred...