@@ -14,6 +14,7 @@ import (
14
14
"time"
15
15
16
16
"github.com/google/go-cmp/cmp"
17
+ "github.com/mongodb/mongo-go-driver/bson/objectid"
17
18
"github.com/mongodb/mongo-go-driver/x/bsonx"
18
19
"github.com/mongodb/mongo-go-driver/x/network/command"
19
20
"github.com/stretchr/testify/require"
@@ -71,6 +72,44 @@ func TestChangeStream_firstStage(t *testing.T) {
71
72
require .NoError (t , err )
72
73
}
73
74
75
+ func TestChangeStream_replaceRoot (t * testing.T ) {
76
+ t .Parallel ()
77
+
78
+ if testing .Short () {
79
+ t .Skip ()
80
+ }
81
+ skipIfBelow36 (t )
82
+
83
+ if os .Getenv ("TOPOLOGY" ) != "replica_set" {
84
+ t .Skip ()
85
+ }
86
+
87
+ coll := createTestCollection (t , nil , nil )
88
+
89
+ // Ensure the database is created.
90
+ _ , err := coll .InsertOne (context .Background (), bsonx.Doc {{"x" , bsonx .Int32 (7 )}})
91
+ require .NoError (t , err )
92
+
93
+ pipeline := make (bsonx.Arr , 0 )
94
+ pipeline = append (pipeline ,
95
+ bsonx .Document (bsonx.Doc {{"$replaceRoot" ,
96
+ bsonx .Document (bsonx.Doc {{"newRoot" ,
97
+ bsonx .Document (bsonx.Doc {{"_id" , bsonx .ObjectID (objectid .New ())}, {"x" , bsonx .Int32 (1 )}})}}),
98
+ }}))
99
+ changes , err := coll .Watch (context .Background (), pipeline )
100
+ require .NoError (t , err )
101
+
102
+ _ , err = coll .InsertOne (context .Background (), bsonx.Doc {{"x" , bsonx .Int32 (4 )}})
103
+ require .NoError (t , err )
104
+
105
+ getNextChange (changes )
106
+ var doc * bsonx.Doc
107
+
108
+ //Ensure the cursor returns an error when the resume token is changed.
109
+ err = changes .Decode (& doc )
110
+ require .Equal (t , err , ErrMissingResumeToken )
111
+ }
112
+
74
113
func TestChangeStream_noCustomStandaloneError (t * testing.T ) {
75
114
t .Parallel ()
76
115
0 commit comments