Skip to content

Commit 3ee634a

Browse files
committed
updated docs for the new overwrite only on matching version bulk insert API
1 parent e4291f5 commit 3ee634a

4 files changed

Lines changed: 63 additions & 39 deletions

File tree

docs/documents/storing.md

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ await theStore.BulkInsertAsync(data, batchSize: 500);
101101
// And just checking that the data is actually there;)
102102
theSession.Query<Target>().Count().ShouldBe(data.Length);
103103
```
104-
<sup><a href='https://github.com/JasperFx/marten/blob/master/src/DocumentDbTests/Writing/bulk_loading.cs#L92-L102' title='Snippet source file'>snippet source</a> | <a href='#snippet-sample_using_bulk_insert' title='Start of snippet'>anchor</a></sup>
104+
<sup><a href='https://github.com/JasperFx/marten/blob/master/src/DocumentDbTests/Writing/bulk_loading.cs#L94-L104' title='Snippet source file'>snippet source</a> | <a href='#snippet-sample_using_bulk_insert' title='Start of snippet'>anchor</a></sup>
105105
<!-- endSnippet -->
106106

107107
The bulk insert is done with a single transaction. For really large document collections, you may need to page the calls to `IDocumentStore.BulkInsert()`.
@@ -126,7 +126,7 @@ await theStore.BulkInsertAsync(data, batchSize: 500);
126126
// And just checking that the data is actually there;)
127127
theSession.Query<Target>().Count().ShouldBe(data.Length);
128128
```
129-
<sup><a href='https://github.com/JasperFx/marten/blob/master/src/DocumentDbTests/Writing/bulk_loading.cs#L250-L260' title='Snippet source file'>snippet source</a> | <a href='#snippet-sample_using_bulk_insert_async' title='Start of snippet'>anchor</a></sup>
129+
<sup><a href='https://github.com/JasperFx/marten/blob/master/src/DocumentDbTests/Writing/bulk_loading.cs#L252-L262' title='Snippet source file'>snippet source</a> | <a href='#snippet-sample_using_bulk_insert_async' title='Start of snippet'>anchor</a></sup>
130130
<!-- endSnippet -->
131131

132132
By default, bulk insert will fail if there are any duplicate id's between the documents being inserted and the existing database data. You can alter this behavior through the `BulkInsertMode` enumeration as shown below:
@@ -150,8 +150,11 @@ await store.BulkInsertDocumentsAsync(data, BulkInsertMode.InsertsOnly);
150150
// Overwrite any existing documents with the same identity as the documents
151151
// being loaded
152152
await store.BulkInsertDocumentsAsync(data, BulkInsertMode.OverwriteExisting);
153+
154+
// Overwrite any existing documents when the expected version matches
155+
await store.BulkInsertDocumentsAsync(data, BulkInsertMode.OverwriteIfVersionMatches);
153156
```
154-
<sup><a href='https://github.com/JasperFx/marten/blob/master/src/DocumentDbTests/Writing/bulk_loading.cs#L329-L348' title='Snippet source file'>snippet source</a> | <a href='#snippet-sample_bulkinsertmode_usages' title='Start of snippet'>anchor</a></sup>
157+
<sup><a href='https://github.com/JasperFx/marten/blob/master/src/DocumentDbTests/Writing/bulk_loading.cs#L331-L353' title='Snippet source file'>snippet source</a> | <a href='#snippet-sample_bulkinsertmode_usages' title='Start of snippet'>anchor</a></sup>
155158
<!-- endSnippet -->
156159

157160
The bulk insert feature can also be used with multi-tenanted documents, but in that
@@ -173,5 +176,20 @@ using var store = DocumentStore.For(opts =>
173176
// If multi-tenanted
174177
await store.BulkInsertDocumentsAsync("a tenant id", data);
175178
```
176-
<sup><a href='https://github.com/JasperFx/marten/blob/master/src/DocumentDbTests/Writing/bulk_loading.cs#L353-L367' title='Snippet source file'>snippet source</a> | <a href='#snippet-sample_multitenancywithbulkinsert' title='Start of snippet'>anchor</a></sup>
179+
<sup><a href='https://github.com/JasperFx/marten/blob/master/src/DocumentDbTests/Writing/bulk_loading.cs#L364-L378' title='Snippet source file'>snippet source</a> | <a href='#snippet-sample_multitenancywithbulkinsert' title='Start of snippet'>anchor</a></sup>
180+
<!-- endSnippet -->
181+
182+
### Bulk Loading with Expected Versions <Badge type="tip" text="8.19" />
183+
184+
There is also a bulk insert mode that will only overwrite the documents _only if_ the version of the document being updated
185+
matches the version being supplied:
186+
187+
<!-- snippet: sample_bulk_insert_with_version_matches -->
188+
<a id='snippet-sample_bulk_insert_with_version_matches'></a>
189+
```cs
190+
await store.BulkInsertDocumentsAsync(data, BulkInsertMode.OverwriteIfVersionMatches);
191+
```
192+
<sup><a href='https://github.com/JasperFx/marten/blob/master/src/DocumentDbTests/Writing/bulk_loading.cs#L355-L359' title='Snippet source file'>snippet source</a> | <a href='#snippet-sample_bulk_insert_with_version_matches' title='Start of snippet'>anchor</a></sup>
177193
<!-- endSnippet -->
194+
195+
See [the documentation on optimistic concurrency and document versioning](/documents/concurrency) for more information.

docs/events/projections/async-daemon.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -220,7 +220,7 @@ You can see the usage below from one of the Marten tests where we use that metho
220220
daemon has caught up:
221221

222222
<!-- snippet: sample_using_WaitForNonStaleProjectionDataAsync -->
223-
<a id='snippet-sample_using_WaitForNonStaleProjectionDataAsync'></a>
223+
<a id='snippet-sample_using_waitfornonstaleprojectiondataasync'></a>
224224
```cs
225225
[Fact]
226226
public async Task run_simultaneously()
@@ -241,7 +241,7 @@ public async Task run_simultaneously()
241241
await CheckExpectedResults();
242242
}
243243
```
244-
<sup><a href='https://github.com/JasperFx/marten/blob/master/src/DaemonTests/EventProjections/event_projections_end_to_end.cs#L28-L49' title='Snippet source file'>snippet source</a> | <a href='#snippet-sample_using_WaitForNonStaleProjectionDataAsync' title='Start of snippet'>anchor</a></sup>
244+
<sup><a href='https://github.com/JasperFx/marten/blob/master/src/DaemonTests/EventProjections/event_projections_end_to_end.cs#L28-L49' title='Snippet source file'>snippet source</a> | <a href='#snippet-sample_using_waitfornonstaleprojectiondataasync' title='Start of snippet'>anchor</a></sup>
245245
<!-- endSnippet -->
246246

247247
The basic idea in your tests is to:
@@ -289,7 +289,7 @@ public async Task run_simultaneously()
289289
The following code shows the diagnostics support for the async daemon as it is today:
290290

291291
<!-- snippet: sample_DaemonDiagnostics -->
292-
<a id='snippet-sample_DaemonDiagnostics'></a>
292+
<a id='snippet-sample_daemondiagnostics'></a>
293293
```cs
294294
public static async Task ShowDaemonDiagnostics(IDocumentStore store)
295295
{
@@ -308,7 +308,7 @@ public static async Task ShowDaemonDiagnostics(IDocumentStore store)
308308
Console.WriteLine($"The daemon high water sequence mark is {daemonHighWaterMark}");
309309
}
310310
```
311-
<sup><a href='https://github.com/JasperFx/marten/blob/master/src/CommandLineRunner/AsyncDaemonBootstrappingSamples.cs#L109-L128' title='Snippet source file'>snippet source</a> | <a href='#snippet-sample_DaemonDiagnostics' title='Start of snippet'>anchor</a></sup>
311+
<sup><a href='https://github.com/JasperFx/marten/blob/master/src/CommandLineRunner/AsyncDaemonBootstrappingSamples.cs#L109-L128' title='Snippet source file'>snippet source</a> | <a href='#snippet-sample_daemondiagnostics' title='Start of snippet'>anchor</a></sup>
312312
<!-- endSnippet -->
313313

314314
## Command Line Support
@@ -429,7 +429,7 @@ from systems using Marten.
429429
If your system is configured to export metrics and Open Telemetry data from Marten like this:
430430

431431
<!-- snippet: sample_enabling_open_telemetry_exporting_from_Marten -->
432-
<a id='snippet-sample_enabling_open_telemetry_exporting_from_Marten'></a>
432+
<a id='snippet-sample_enabling_open_telemetry_exporting_from_marten'></a>
433433
```cs
434434
// This is passed in by Project Aspire. The exporter usage is a little
435435
// different for other tools like Prometheus or SigNoz
@@ -448,7 +448,7 @@ builder.Services.AddOpenTelemetry()
448448
metrics.AddMeter("Marten");
449449
});
450450
```
451-
<sup><a href='https://github.com/JasperFx/marten/blob/master/src/samples/AspireHeadlessTripService/Program.cs#L21-L40' title='Snippet source file'>snippet source</a> | <a href='#snippet-sample_enabling_open_telemetry_exporting_from_Marten' title='Start of snippet'>anchor</a></sup>
451+
<sup><a href='https://github.com/JasperFx/marten/blob/master/src/samples/AspireHeadlessTripService/Program.cs#L21-L40' title='Snippet source file'>snippet source</a> | <a href='#snippet-sample_enabling_open_telemetry_exporting_from_marten' title='Start of snippet'>anchor</a></sup>
452452
<!-- endSnippet -->
453453

454454
*And* you are running the async daemon in your system, you should see potentially activities for each running projection

0 commit comments

Comments
 (0)