4

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:

enter image description 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())

enter image description here

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?

Itay Livni
  • 2,143
  • 24
  • 38

1 Answers1

1

The below error

OperationFailure: Unrecognized pipeline stage name: '$changeStream'

Indicates that your Mongodb server is below 3.6.0 and that is why it doesn't recognize this command. Even though you have latest client, doesn't change how the server behaves

Tarun Lalwani
  • 142,312
  • 9
  • 204
  • 265
  • So there is no way to use this operation with MongoDB Atlas? The server version on Mongo's cloud service is defaulting to is 3.4.14. :( – Itay Livni Mar 26 '18 at 18:05
  • `Atlas supports creating M10+ paid tier clusters with the following MongoDB versions: MongoDB 3.2 MongoDB 3.4 MongoDB 3.6 M0 Free Tier and M2/M5 shared tier clusters only support MongoDB 3.4.` – Tarun Lalwani Mar 26 '18 at 18:07