Я пытаюсь запустить операцию FindAndModify в MongoDB, но получаю необычное исключение
var query = Query.EQ("_id", wiki.ID);
var sortBy = SortBy.Descending("Version");
var update = Update.Set("Content", wiki.Content)
.Set("CreatedBy", wiki.CreatedBy)
.Set("CreatedDate", wiki.CreatedDate)
.Set("Name", wiki.Name)
.Set("PreviousVersion", wiki.PreviousVersion.ToBsonDocument())
.Set("Title", wiki.Title)
.Set("Version", wiki.Version);
var result = collection.FindAndModify(query, sortBy, update, true);
Исключение, которое я получаю:
WriteStartArray can only be called when State is Value, not when State is Initial
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.InvalidOperationException: WriteStartArray can only be called when State is Value, not when State is Initial
Source Error:
Line 45: var query = Query.EQ("_id", wiki.ID);
Line 46: var sortBy = SortBy.Descending("Version");
Line 47: var update = Update.Set("Content", wiki.Content)
Line 48: .Set("CreatedBy", wiki.CreatedBy)
Line 49: .Set("CreatedDate", wiki.CreatedDate)
Мысли?Я реализовал это в соответствии с API на сайте mongodb.
EDIT-- Исправлено per @ jeffsaracco
var update = Update.Set("Content", wiki.Content)
.Set("CreatedBy", wiki.CreatedBy)
.Set("CreatedDate", wiki.CreatedDate)
.Set("Name", wiki.Name)
.PushAllWrapped<WikiHistory>("PreviousVersion", wiki.PreviousVersion)
.Set("Title", wiki.Title)
.Set("Version", wiki.Version);