简体   繁体   English

如何在pymongo文档中查看更新的布尔值?

[英]How to watch for an updated boolean value in a pymongo document?

I am trying to listen for an update to a collection using pymongo 3.6.1 . 我正在尝试使用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. 如果在任何文档中将关键Success更新为true 则会调用def dosomething()

The mongodb api documentation shows this example, as a first step: mongodb api文档显示了这个例子,作为第一步:

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. 在尝试复制这个时,我得到一个OperationFailure: Unrecognized pipeline stage name: '$changeStream'错误。 When researching other's with similar issues on stack The answer was connection driver versions. 在堆栈上研究其他类似问题的答案是connection driver版本。 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? 如何监听MongoDB集合的变化? https://docs.mongodb.com/master/changeStreams/ https://docs.mongodb.com/master/changeStreams/

What is the right approach? 什么是正确的方法?

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. 表示您的Mongodb服务器低于3.6.0 ,这就是它无法识别此命令的原因。 Even though you have latest client, doesn't change how the server behaves 即使您拥有最新的客户端,也不会更改服务器的行为方式

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM