Struct MongoDbCdcPosition
Represents a position in the MongoDB change stream using a resume token.
public readonly struct MongoDbCdcPosition : IEquatable<MongoDbCdcPosition>
- Implements
- Inherited Members
Remarks
The resume token is an opaque MongoDB.Bson.BsonDocument provided by MongoDB that allows resuming a change stream from a specific point.
Constructors
MongoDbCdcPosition(BsonDocument?)
Initializes a new instance of the MongoDbCdcPosition struct for an ordinary
checkpoint, reopened with resumeAfter.
public MongoDbCdcPosition(BsonDocument? resumeToken)
Parameters
resumeTokenBsonDocumentThe resume token from a change stream event.
MongoDbCdcPosition(BsonDocument?, MongoDbChangeStreamResumeMode)
Initializes a new instance of the MongoDbCdcPosition struct.
public MongoDbCdcPosition(BsonDocument? resumeToken, MongoDbChangeStreamResumeMode resumeMode)
Parameters
resumeTokenBsonDocumentThe resume token from a change stream event.
resumeModeMongoDbChangeStreamResumeModeWhich change-stream option this token must be reopened with. A token taken from an
invalidateevent is only usable as StartAfter.
Fields
Start
Represents the start position (no resume token).
public static readonly MongoDbCdcPosition Start
Field Value
Properties
IsValid
Gets a value indicating whether this position is valid (has a resume token).
public bool IsValid { get; }
Property Value
ResumeMode
Gets the change-stream option this token must be reopened with.
public MongoDbChangeStreamResumeMode ResumeMode { get; }
Property Value
ResumeToken
Gets the resume token as a BSON document.
public BsonDocument? ResumeToken { get; }
Property Value
- BsonDocument
TokenString
Gets the resume token as a JSON string for storage/serialization.
public string? TokenString { get; }
Property Value
Remarks
A StartAfter position serializes as an envelope
carrying both the token and the mode, because a restarted process that reopened such a token with
resumeAfter would land back before the invalidation it had already passed.
Methods
Equals(MongoDbCdcPosition)
Indicates whether the current object is equal to another object of the same type.
public bool Equals(MongoDbCdcPosition other)
Parameters
otherMongoDbCdcPositionAn object to compare with this object.
Returns
Equals(object?)
Indicates whether this instance and a specified object are equal.
public override bool Equals(object? obj)
Parameters
objobjectThe object to compare with the current instance.
Returns
- bool
true if
objand this instance are the same type and represent the same value; otherwise, false.
FromChangePosition(ChangePosition?)
Creates a MongoDbCdcPosition from a ChangePosition.
public static MongoDbCdcPosition FromChangePosition(ChangePosition? position)
Parameters
positionChangePositionThe change position to convert.
Returns
- MongoDbCdcPosition
A MongoDbCdcPosition parsed from the token.
FromString(string?)
Creates a position from a JSON string representation of the resume token.
public static MongoDbCdcPosition FromString(string? tokenString)
Parameters
tokenStringstringThe JSON string representation.
Returns
GetHashCode()
Returns the hash code for this instance.
public override int GetHashCode()
Returns
- int
A 32-bit signed integer that is the hash code for this instance.
ToChangePosition()
Converts this position to a ChangePosition for use with the unified ICdcStateStore contract.
public ChangePosition ToChangePosition()
Returns
- ChangePosition
A TokenChangePosition representing this position.
ToString()
Returns the fully qualified type name of this instance.
public override string ToString()
Returns
- string
The fully qualified type name.
TryParse(string?, out MongoDbCdcPosition)
Tries to parse a JSON string into a MongoDbCdcPosition.
public static bool TryParse(string? tokenString, out MongoDbCdcPosition result)
Parameters
tokenStringstringThe JSON string to parse.
resultMongoDbCdcPositionThe parsed position if successful.
Returns
- bool
True if parsing succeeded; otherwise, false.
Operators
operator ==(MongoDbCdcPosition, MongoDbCdcPosition)
Determines whether two positions are equal.
public static bool operator ==(MongoDbCdcPosition left, MongoDbCdcPosition right)
Parameters
leftMongoDbCdcPositionrightMongoDbCdcPosition
Returns
operator !=(MongoDbCdcPosition, MongoDbCdcPosition)
Determines whether two positions are not equal.
public static bool operator !=(MongoDbCdcPosition left, MongoDbCdcPosition right)
Parameters
leftMongoDbCdcPositionrightMongoDbCdcPosition