Change Streams
Change Streams
Section titled “Change Streams”Pie provides change stream functionality for real-time data monitoring.
Basic Usage
Section titled “Basic Usage”// Create change stream watcherwatcher := pie.NewWatcher[User](engine)
// Watch collection changeserr := watcher. WatchCollection(). Start(ctx, func(change *pie.ChangeEvent[User]) error { log.Printf("Change type: %s", change.OperationType) log.Printf("Document ID: %s", change.DocumentKey)
switch change.OperationType { case "insert": log.Printf("New user inserted: %s", change.FullDocument.Name) case "update": log.Printf("User updated: %s", change.FullDocument.Name) case "delete": log.Printf("User deleted: %s", change.DocumentKey) }
return nil })Next Steps
Section titled “Next Steps”- Query Scopes - Learn about query scopes
- Logging & Monitoring - Learn about logging
- Best Practices - Learn development best practices