File tree Expand file tree Collapse file tree 1 file changed +31
-0
lines changed
Expand file tree Collapse file tree 1 file changed +31
-0
lines changed Original file line number Diff line number Diff line change @@ -39,6 +39,37 @@ type ChangeStreamOptions struct {
3939 Collation * Collation
4040}
4141
42+ // Watch constructs a new ChangeStream capable of receiving continuing data
43+ // from the database.
44+ func (coll * Collection ) Watch (pipeline interface {},
45+ options ChangeStreamOptions ) (* ChangeStream , error ) {
46+
47+ if pipeline == nil {
48+ pipeline = []bson.M {}
49+ }
50+
51+ pipe := constructChangeStreamPipeline (pipeline , options )
52+
53+ pIter := coll .Pipe (& pipe ).Iter ()
54+
55+ // check that there was no issue creating the iterator.
56+ // this will fail immediately with an error from the server if running against
57+ // a standalone.
58+ if err := pIter .Err (); err != nil {
59+ return nil , err
60+ }
61+
62+ pIter .isChangeStream = true
63+
64+ return & ChangeStream {
65+ iter : pIter ,
66+ collection : coll ,
67+ resumeToken : nil ,
68+ options : options ,
69+ pipeline : pipeline ,
70+ }, nil
71+ }
72+
4273// Next retrieves the next document from the change stream, blocking if necessary.
4374// Next returns true if a document was successfully unmarshalled into result,
4475// and false if an error occured. When Next returns false, the Err method should
You can’t perform that action at this time.
0 commit comments