Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions internal/integration/change_stream_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
2 changes: 2 additions & 0 deletions internal/integration/cursor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
5 changes: 5 additions & 0 deletions mongo/change_stream.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
//
Expand Down
5 changes: 5 additions & 0 deletions mongo/cursor.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
Loading