Immediate feedback is an essential part of modern application development where developers want to sync across platforms, systems, and users to provide better end-user experiences. Change streams empower developers to easily leverage the power of MongoDB's internal real-time functionality to react to relevant data changes immediately. Change streams also provide the backbone of MongoDB Atlas triggers. This session introduces change streams and walks you through developing with them. We will discuss use cases, integrating with Kafka, and explore how to make good architectural decisions around this new functionality.
43. 1. Present a Defined API
NodeJS let changestream = db.collection("orders").watch()
changestream.on("change", (event) => { console.log(event) })
Python changestream = db.orders.watch()
for event in changestream:
print event
C++ auto changestream = db["orders"].watch();
for (auto& event : changestream) {
cout << to_json(event) << endl;
}
51. 1. Defined API
2. Access Controls
3. Use on any Data Bearing Node
4. Total Ordering
5. Uniquely Identifies Documents
6. Durable
7. Resumable
8. Aggregation
55. Iterate to get events (blocking)
doc = change_stream.next()
for doc in change_stream.next()
Set polling frequency
change_stream = coll.watch (maxAwaitTimeMS=500)
61. collection.watch()
Insert, Update, Replace, Delete on the collection.
Drop/Rename on the collection. Always followed by an Invalidate.
Invalidate on when collection dropped or renamed. Closes connection.
62. database.watch()
Insert, Update, Replace, Delete on all nested collections.
Drop/Rename on all nested collections. Not followed by an invalidate.
Invalidate on when database dropped. Closes connection.
DropDatabase when database dropped. Always followed by an invalidate.
63. client.watch()
Insert, Update, Replace, Delete on all databases and collections.
Drop/Rename on all collections.
Invalidate on all databases and collections. Does not close connection.
DropDatabase on all databases.