Last active
October 22, 2019 16:00
-
-
Save shantanoo-desai/44c2fc021b46d3db70ef1a92e2304917 to your computer and use it in GitHub Desktop.
Change Stream for MongoDB using Windows 10, Docker, MongoDB and pymongo snippet
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Change Stream Example | |
# using PYMONGO v3.9.0 | |
import sys | |
import pprint | |
from pymongo import MongoClient | |
# Create a Client to our Replica Set | |
cl = MongoClient(host='localhost', port=37017, replicaSet='rs0') | |
# Database: `team` # Collection: `players` | |
db = cl['team'] | |
# using `watch()` for change streams in pymongo | |
try: | |
with db['players'].watch() as change_stream: | |
for change in change_stream: | |
pprint.pprint(change) ## should pretty print the newly inserted doc | |
except KeyboardInterrupt: | |
cl.close() | |
sys.exit() | |
except Exception as e: | |
print(e) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment