OperationVetoedException - 更新现有(唯一)文档时

时间:2012-11-21 14:07:42

标签: .net ravendb unique-constraint

当我尝试更新RavenDB数据库中的文档时,我收到了OperationVetoedException。

我的RavenDB版本和UniqueConstraintsBundle是960(并且从未在任何先前版本中更新过。)

我已经检查过,但在数据库中找不到任何重复项。所以我不明白这个错误是怎么可能的。

下面我的代码示例中的列表oldVisitorSessions仅包含唯一对象。

代码

using (var session = _documentStore.OpenSession())
{
    foreach (var visitorSession in oldVisitorSessions)
    {
        visitorSession.ProspectType = string.Empty;
        session.Store(visitorSession);
    }

    session.SaveChanges();
}

异常

Url: "/bulk_docs"
Raven.Database.Exceptions.OperationVetoedException: PUT vetoed by Raven.Bundles.UniqueConstraints.UniqueConstraintsPutTrigger because: Ensure unique constraint violated for fields: session_id
   at Raven.Database.DocumentDatabase.AssertPutOperationNotVetoed(String key, RavenJObject metadata, RavenJObject document, TransactionInformation transactionInformation) in c:\Builds\RavenDB-Stable\Raven.Database\DocumentDatabase.cs:line 522
   at Raven.Database.DocumentDatabase.<>c__DisplayClass37.<Put>b__30(IStorageActionsAccessor actions) in c:\Builds\RavenDB-Stable\Raven.Database\DocumentDatabase.cs:line 476
   at Raven.Storage.Esent.TransactionalStorage.Batch(Action`1 action) in c:\Builds\RavenDB-Stable\Raven.Storage.Esent\TransactionalStorage.cs:line 330
   at Raven.Database.DocumentDatabase.Put(String key, Nullable`1 etag, RavenJObject document, RavenJObject metadata, TransactionInformation transactionInformation) in c:\Builds\RavenDB-Stable\Raven.Database\DocumentDatabase.cs:line 468
   at Raven.Database.Extensions.CommandExtensions.Execute(ICommandData self, DocumentDatabase database) in c:\Builds\RavenDB-Stable\Raven.Database\Extensions\CommandExtensions.cs:line 25
   at Raven.Database.DocumentDatabase.<>c__DisplayClassca.<Batch>b__c6(IStorageActionsAccessor actions) in c:\Builds\RavenDB-Stable\Raven.Database\DocumentDatabase.cs:line 1196
   at Raven.Storage.Esent.TransactionalStorage.ExecuteBatch(Action`1 action) in c:\Builds\RavenDB-Stable\Raven.Storage.Esent\TransactionalStorage.cs:line 376
   at Raven.Storage.Esent.TransactionalStorage.Batch(Action`1 action) in c:\Builds\RavenDB-Stable\Raven.Storage.Esent\TransactionalStorage.cs:line 337
   at Raven.Database.DocumentDatabase.Batch(IEnumerable`1 commands) in c:\Builds\RavenDB-Stable\Raven.Database\DocumentDatabase.cs:line 1192
   at Raven.Database.Server.Responders.DocumentBatch.Batch(IHttpContext context) in c:\Builds\RavenDB-Stable\Raven.Database\Server\Responders\DocumentBatch.cs:line 94
   at Raven.Database.Server.Responders.DocumentBatch.Respond(IHttpContext context) in c:\Builds\RavenDB-Stable\Raven.Database\Server\Responders\DocumentBatch.cs:line 38
   at Raven.Database.Server.HttpServer.DispatchRequest(IHttpContext ctx) in c:\Builds\RavenDB-Stable\Raven.Database\Server\HttpServer.cs:line 550
   at Raven.Database.Server.HttpServer.HandleActualRequest(IHttpContext ctx) in c:\Builds\RavenDB-Stable\Raven.Database\Server\HttpServer.cs:line 316

1 个答案:

答案 0 :(得分:0)

请注意,'session_id'上有一个唯一约束失败,很可能你将它设置为null,对吗? 还有另一件事也是空的。