diff --git a/internal/integration/change_stream_test.go b/internal/integration/change_stream_test.go index 245174a6d0..a519249da2 100644 --- a/internal/integration/change_stream_test.go +++ b/internal/integration/change_stream_test.go @@ -379,6 +379,8 @@ func TestChangeStream_ReplicaSet(t *testing.T) { for i := 0; i < numExpectedEvents; i++ { assert.True(mt, cs.Next(context.Background()), "expected Next to return true, got false") + assert.Equal(mt, cs.CurrentRaw(), cs.Current, "CurrentRaw should return Current") + // while we're not at the last doc in the batch, the resume token should be the _id of the // document if i != numExpectedEvents-1 { diff --git a/internal/integration/cursor_test.go b/internal/integration/cursor_test.go index 94acd222c5..a539d317af 100644 --- a/internal/integration/cursor_test.go +++ b/internal/integration/cursor_test.go @@ -110,6 +110,8 @@ func TestCursor_TryNext(t *testing.T) { // first call to TryNext should return 1 document assert.True(mt, cursor.TryNext(context.Background()), "expected Next to return true, got false") + assert.Equal(mt, cursor.CurrentRaw(), cursor.Current, "CurrentRaw should return Current") + // TryNext should attempt one getMore mt.ClearEvents() assert.False(mt, cursor.TryNext(context.Background()), "unexpected document %v", cursor.Current) diff --git a/mongo/change_stream.go b/mongo/change_stream.go index d5ad8058ec..d7b7472127 100644 --- a/mongo/change_stream.go +++ b/mongo/change_stream.go @@ -602,6 +602,11 @@ func (cs *ChangeStream) ResumeToken() bson.Raw { return cs.resumeToken } +// CurrentRaw returns the Current struct member. +func (c *ChangeStream) CurrentRaw() bson.Raw { + return c.Current +} + // Next gets the next event for this change stream. It returns true if there // were no errors and the next event document is available. // diff --git a/mongo/cursor.go b/mongo/cursor.go index bb77f4a21e..9e6942b2c5 100644 --- a/mongo/cursor.go +++ b/mongo/cursor.go @@ -185,6 +185,11 @@ func (c *Cursor) Next(ctx context.Context) bool { return c.next(ctx, false) } +// CurrentRaw returns the Current struct member. +func (c *Cursor) CurrentRaw() bson.Raw { + return c.Current +} + // TryNext attempts to get the next document for this cursor. It returns true if there were no errors and the next // document is available. This is only recommended for use with tailable cursors as a non-blocking alternative to // Next. See https://www.mongodb.com/docs/manual/core/tailable-cursors/ for more information about tailable cursors.