|
|
|
@ -40,16 +40,11 @@ namespace Squidex.Infrastructure.MongoDb |
|
|
|
{ |
|
|
|
await collection.InsertOneAsync(document, null, ct); |
|
|
|
} |
|
|
|
catch (MongoWriteException ex) |
|
|
|
{ |
|
|
|
if (ex.WriteError.Category == ServerErrorCategory.DuplicateKey) |
|
|
|
catch (MongoWriteException ex) when (ex.WriteError?.Category == ServerErrorCategory.DuplicateKey) |
|
|
|
{ |
|
|
|
return false; |
|
|
|
} |
|
|
|
|
|
|
|
throw; |
|
|
|
} |
|
|
|
|
|
|
|
return true; |
|
|
|
} |
|
|
|
|
|
|
|
@ -108,9 +103,7 @@ namespace Squidex.Infrastructure.MongoDb |
|
|
|
await collection.UpdateOneAsync(x => x.Id.Equals(key), update, Upsert); |
|
|
|
} |
|
|
|
} |
|
|
|
catch (MongoWriteException ex) |
|
|
|
{ |
|
|
|
if (ex.WriteError.Category == ServerErrorCategory.DuplicateKey) |
|
|
|
catch (MongoWriteException ex) when (ex.WriteError?.Category == ServerErrorCategory.DuplicateKey) |
|
|
|
{ |
|
|
|
var existingVersion = |
|
|
|
await collection.Find(x => x.Id.Equals(key)).Only(x => x.Id, x => x.Version) |
|
|
|
@ -122,10 +115,9 @@ namespace Squidex.Infrastructure.MongoDb |
|
|
|
|
|
|
|
throw new InconsistentStateException(existingVersion[versionField].AsInt64, oldVersion, ex); |
|
|
|
} |
|
|
|
} |
|
|
|
else |
|
|
|
{ |
|
|
|
throw; |
|
|
|
throw new InconsistentStateException(EtagVersion.Any, oldVersion, ex); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
@ -145,9 +137,7 @@ namespace Squidex.Infrastructure.MongoDb |
|
|
|
await collection.ReplaceOneAsync(x => x.Id.Equals(key), doc, UpsertReplace); |
|
|
|
} |
|
|
|
} |
|
|
|
catch (MongoWriteException ex) |
|
|
|
{ |
|
|
|
if (ex.WriteError.Category == ServerErrorCategory.DuplicateKey) |
|
|
|
catch (MongoWriteException ex) when (ex.WriteError?.Category == ServerErrorCategory.DuplicateKey) |
|
|
|
{ |
|
|
|
var existingVersion = |
|
|
|
await collection.Find(x => x.Id.Equals(key)).Only(x => x.Id, x => x.Version) |
|
|
|
@ -159,10 +149,9 @@ namespace Squidex.Infrastructure.MongoDb |
|
|
|
|
|
|
|
throw new InconsistentStateException(existingVersion[versionField].AsInt64, oldVersion, ex); |
|
|
|
} |
|
|
|
} |
|
|
|
else |
|
|
|
{ |
|
|
|
throw; |
|
|
|
throw new InconsistentStateException(EtagVersion.Any, oldVersion, ex); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|