Nâng CaoMongoDB iconMongoDB

Change streams trong MongoDB dùng khi nào?

Change streams cho phép app subscribe changes từ collection/database/cluster để build realtime features, cache invalidation, audit pipeline, sync sang search index hoặc event-driven projection.

Ví dụ Node.js:

javascript
const stream = db.collection("orders").watch()
for await (const change of stream) {
  console.log(change.operationType, change.documentKey)
}

Production cần resume token, error handling, idempotent consumers và monitoring lag.

Không nên coi change stream là magic queue nếu chưa thiết kế retry/dedup.

Xem toàn bộ MongoDB cùng filter theo level & chủ đề con.

Mở danh sách MongoDB