简体   繁体   中英

Create mongo change stream in the mongo shell

MongoDB introduced change streams in their 3.6 release.
I wanted to implement mongo change stream in my code and wanted to understand how it works. I will implement using the java driver and it's pretty clear. But I wanted to know if there is there any way to open a change stream on in the mongo shell? Couldn't find much resources on that.

The db.collection.watch command opens ac hange stream cursor .

For example:

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

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

Plenty more detail in the docs .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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