I am trying to listen for an update to a collection using pymongo 3.6.1
.
The collection gets updated with a document that looks something like this:
{"End_Word":"bit","Success":true,"Score":1,"Term_Index":5}
Where if the key Success
gets updated to true
in any of the documents a def dosomething()
gets called.
The mongodb api documentation shows this example, as a first step:
with db.collection.watch() as stream:
for change in stream:
print(change)
In attempting to replicate this I am getting a OperationFailure: Unrecognized pipeline stage name: '$changeStream'
error. When researching other's with similar issues on stack The answer was connection driver
versions. I don't think this is the case here:
Code:
db_name = 'mapstore'
coll_name = 'oxygen'
MONGO_DB_DRIVER = pymongo atlas M2 instance driver
conn = pymongo.MongoClient(MONGO_DB_DRIVER)
db = conn[db_name]
print(db.collection_names())
Update:
I also looked in these places
How to listen for changes to a MongoDB collection? https://docs.mongodb.com/master/changeStreams/
What is the right approach?