|
|
|
@ -168,11 +168,6 @@ public static class MongoExtensions |
|
|
|
var (key, snapshot, _, oldVersion) = job; |
|
|
|
try |
|
|
|
{ |
|
|
|
Expression<Func<T, bool>> filter2 = |
|
|
|
oldVersion > EtagVersion.Any ? |
|
|
|
x => x.DocumentId.Equals(key) && x.Version == oldVersion : |
|
|
|
x => x.DocumentId.Equals(key); |
|
|
|
|
|
|
|
var filter = filters.Eq(x => x.DocumentId, key); |
|
|
|
|
|
|
|
if (oldVersion > EtagVersion.Any) |
|
|
|
@ -182,6 +177,20 @@ public static class MongoExtensions |
|
|
|
|
|
|
|
var result = await collection.ReplaceOneAsync(filter, job.Value, UpsertReplace, ct); |
|
|
|
|
|
|
|
if (result.IsAcknowledged && result.ModifiedCount == 0 && oldVersion > EtagVersion.Any) |
|
|
|
{ |
|
|
|
var existingVersion = |
|
|
|
await collection.Find(filters.Eq("_id", key)) |
|
|
|
.Project<BsonDocument>(Builders<T>.Projection.Include("_id").Include(versionField)) |
|
|
|
.FirstOrDefaultAsync(ct); |
|
|
|
|
|
|
|
var currentVersion = existingVersion != null |
|
|
|
? existingVersion[Field.Of<T>(x => nameof(x.Version))].AsInt64 |
|
|
|
: EtagVersion.Any; |
|
|
|
|
|
|
|
throw new InconsistentStateException(currentVersion, oldVersion); |
|
|
|
} |
|
|
|
|
|
|
|
return result.IsAcknowledged && result.ModifiedCount == 1; |
|
|
|
} |
|
|
|
catch (MongoWriteException ex) when (ex.WriteError?.Category == ServerErrorCategory.DuplicateKey) |
|
|
|
|