Any plan on Upserting ?
See original GitHub issueDo you plan on adding upserting methods like in MongoDB ? Like in this example :
Foo foo = ...
var replaceOneResult = await collection.ReplaceOneAsync(
doc => doc.Id == foo.Id,
foo,
new UpdateOptions {IsUpsert = true});
Much thanks for this useful library.
Issue Analytics
- State:
- Created 8 years ago
- Reactions:3
- Comments:9 (3 by maintainers)
Top Results From Across the Web
any plan of implementing 'UPSERT' or 'ON DUPLICATE ...
sql: any plan of implementing 'UPSERT' or 'ON DUPLICATE KEY UPDATE' ? #1962 ... Postgresql has its own implementation of "Upsert".
Read more >Upserting objects in Apex: can I assert which have been ...
I'm upserting a list of custom objects in an Apex controller that are retrieved on demand from an external source. My object has...
Read more >Upserting Records | Apex Developer Guide
Using the upsert operation, you can either insert or update an existing record ... a task for the owner(s) of any leads that...
Read more >UPSERT
The UPSERT statement inserts rows when values do not violate uniqueness constraints, and it updates rows when values do violate uniqueness constraints.
Read more >Elasticsearch Upsert: Performing Upsert Operations, with ...
In Elasticsearch, upsert is a powerful operation that allows you to perform both update and insert actions in a single request.
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Just adding my 👍 to this request; it’s a really useful feature when designing idempotent workloads.
My current ‘workaround’ (which is really more of pretty code than efficient):
collection.InsertBulk(documentsToUpsert.Where(d => !collection.Update(d)).ToList());
I’ve been working with a basic extension method to take the place of this behaviour until such a time when it is truly available. Here’s a simple implementation which relies on the type having an ID field that LiteDB can map correctly, or a mapping entry for the type in question that handles keying said objects. If the keys are equal, the item will be upserted. In short, it’s really an Update call followed by an Insert call on failure, but it works for me in cases where performance aren’t super critical. Implementation available here