Open CatsWithoutDirection opened 2 years ago
Also happened to me. After checking the code, I found this in LiteDB/Engine/Engine/Upsert.cs
:
foreach (var doc in docs)
{
transaction.Safepoint();
// first try update document (if exists _id), if not found, do insert
if (doc["_id"] == BsonValue.Null || this.UpdateDocument(snapshot, collectionPage, doc, indexer, data) == false)
{
this.InsertDocument(snapshot, doc, autoId, indexer, data);
count++;
}
}
The updated documents are not included when counting. (And LiteCollection.Upsert
just compared the result to 1
so it returns false
.)
So this might be intentionally designed. But I still think it is highly misleading, especially when the document says nothing about the result.
Version 5.0.1 Describe the bug Upsert Returns always False while it upsert successfully Code to Reproduce MakerSureConfigTypeHasNoId(typeof(TConfig)); var result = Db.GetCollection(typeof(TConfig).Name).Upsert(SingleId, config);
Console.WriteLine($"Upsert Result:{result}");
return result;
Expected behavior
i hope it could return write return
Screenshots/Stacktrace
Additional context There is another problem that when i use the method several times continuously ,it wont work for some "Set" except the first