gpt4 book ai didi

mongodb - 在 mongo shell 中创建 mongo 更改流

转载 作者:行者123 更新时间:2023-12-05 01:43:45 24 4
gpt4 key购买 nike

MongoDB 介绍 change streams在他们的 3.6 版本中。
我想在我的代码中实现 mongo change stream,并想了解它是如何工作的。我将使用 java 驱动程序实现,这很清楚。但我想知道是否有任何方法可以在 mongo shell 中打开更改流?找不到太多相关资源。

最佳答案

db.collection.watch 命令打开一个 c hange stream cursor .

例如:

watchCursor = db.getSiblingDB("data").sensors.watch(
[
{ $match : {"operationType" : "insert" } }
]
)

while (!watchCursor.isExhausted()){
if (watchCursor.hasNext()){
print(tojson(watchCursor.next()));
}
}

更多细节 in the docs .

关于mongodb - 在 mongo shell 中创建 mongo 更改流,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48299809/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com