Skip to content

Commit

Permalink
fix merge conflicts
Browse files Browse the repository at this point in the history
  • Loading branch information
elexisvenator committed Oct 3, 2024
1 parent 1097e8f commit de915ee
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 6 deletions.
10 changes: 5 additions & 5 deletions docs/documents/storing.md
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ theStore.BulkInsert(data, batchSize: 500);
// And just checking that the data is actually there;)
theSession.Query<Target>().Count().ShouldBe(data.Length);
```
<sup><a href='https://github.com/JasperFx/marten/blob/master/src/DocumentDbTests/Writing/bulk_loading.cs#L147-L157' title='Snippet source file'>snippet source</a> | <a href='#snippet-sample_using_bulk_insert' title='Start of snippet'>anchor</a></sup>
<sup><a href='https://github.com/JasperFx/marten/blob/master/src/DocumentDbTests/Writing/bulk_loading.cs#L146-L156' title='Snippet source file'>snippet source</a> | <a href='#snippet-sample_using_bulk_insert' title='Start of snippet'>anchor</a></sup>
<!-- endSnippet -->

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

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:
Expand All @@ -151,7 +151,7 @@ await store.BulkInsertDocumentsAsync(data, BulkInsertMode.InsertsOnly);
// being loaded
await store.BulkInsertDocumentsAsync(data, BulkInsertMode.OverwriteExisting);
```
<sup><a href='https://github.com/JasperFx/marten/blob/master/src/DocumentDbTests/Writing/bulk_loading.cs#L384-L403' title='Snippet source file'>snippet source</a> | <a href='#snippet-sample_BulkInsertMode_usages' title='Start of snippet'>anchor</a></sup>
<sup><a href='https://github.com/JasperFx/marten/blob/master/src/DocumentDbTests/Writing/bulk_loading.cs#L383-L402' title='Snippet source file'>snippet source</a> | <a href='#snippet-sample_BulkInsertMode_usages' title='Start of snippet'>anchor</a></sup>
<!-- endSnippet -->

When using `BulkInsertMode.OverwriteExisting` it is also possible to pass in a condition to be evaluated when overwriting documents.
Expand All @@ -169,7 +169,7 @@ await theStore.BulkInsertAsync(
BulkInsertMode.OverwriteExisting,
updateCondition: "(d.data ->> 'Number')::int <= (excluded.data ->> 'Number')::int");
```
<sup><a href='https://github.com/JasperFx/marten/blob/master/src/DocumentDbTests/Writing/bulk_loading.cs#L123-L133' title='Snippet source file'>snippet source</a> | <a href='#snippet-sample_BulkInsertWithUpdateCondition' title='Start of snippet'>anchor</a></sup>
<sup><a href='https://github.com/JasperFx/marten/blob/master/src/DocumentDbTests/Writing/bulk_loading.cs#L101-L111' title='Snippet source file'>snippet source</a> | <a href='#snippet-sample_BulkInsertWithUpdateCondition' title='Start of snippet'>anchor</a></sup>
<!-- endSnippet -->

The bulk insert feature can also be used with multi-tenanted documents, but in that
Expand All @@ -191,5 +191,5 @@ using var store = DocumentStore.For(opts =>
// If multi-tenanted
await store.BulkInsertDocumentsAsync("a tenant id", data);
```
<sup><a href='https://github.com/JasperFx/marten/blob/master/src/DocumentDbTests/Writing/bulk_loading.cs#L408-L422' title='Snippet source file'>snippet source</a> | <a href='#snippet-sample_MultiTenancyWithBulkInsert' title='Start of snippet'>anchor</a></sup>
<sup><a href='https://github.com/JasperFx/marten/blob/master/src/DocumentDbTests/Writing/bulk_loading.cs#L407-L421' title='Snippet source file'>snippet source</a> | <a href='#snippet-sample_MultiTenancyWithBulkInsert' title='Start of snippet'>anchor</a></sup>
<!-- endSnippet -->
12 changes: 11 additions & 1 deletion src/DocumentDbTests/Writing/bulk_loading.cs
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,17 @@ public void load_with_overwrite_duplicates_and_update_condition()
.Select((t, i) => t with { Number = i < 10 ? 50 : 150, String = "second insert" })
.ToArray();

theStore.BulkInsert(data2, BulkInsertMode.OverwriteExisting, updateCondition: "(d.data ->> 'Number')::int <= (excluded.data ->> 'Number')::int");
#region sample_BulkInsertWithUpdateCondition

// perform a bulk insert of `Target` documents
// but only overwrite existing if the existing document's "Number"
// property is less then the new document's
await theStore.BulkInsertAsync(
data2,
BulkInsertMode.OverwriteExisting,
updateCondition: "(d.data ->> 'Number')::int <= (excluded.data ->> 'Number')::int");

#endregion

using var session = theStore.QuerySession();
session.Query<Target>().Count().ShouldBe(data1.Length);
Expand Down

0 comments on commit de915ee

Please sign in to comment.