Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

<groupId>org.springframework.data</groupId>
<artifactId>spring-data-mongodb-parent</artifactId>
<version>4.5.0-SNAPSHOT</version>
<version>4.5.0-GH-4944-SNAPSHOT</version>
<packaging>pom</packaging>

<name>Spring Data MongoDB</name>
Expand Down
2 changes: 1 addition & 1 deletion spring-data-mongodb-distribution/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
<parent>
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-mongodb-parent</artifactId>
<version>4.5.0-SNAPSHOT</version>
<version>4.5.0-GH-4944-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>

Expand Down
2 changes: 1 addition & 1 deletion spring-data-mongodb/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
<parent>
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-mongodb-parent</artifactId>
<version>4.5.0-SNAPSHOT</version>
<version>4.5.0-GH-4944-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1433,7 +1433,10 @@ protected <T> Collection<T> doInsertBatch(String collectionName, Collection<? ex
maybeEmitEvent(new BeforeSaveEvent<>(initialized, document, collectionName));
initialized = maybeCallBeforeSave(initialized, document, collectionName);

documentList.add(document);
MappedDocument mappedDocument = queryOperations.createInsertContext(MappedDocument.of(document))
.prepareId(uninitialized.getClass());

documentList.add(mappedDocument.getDocument());
initializedBatchToSave.add(initialized);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
import java.util.stream.IntStream;
import java.util.stream.Stream;

import org.bson.Document;
import org.bson.types.ObjectId;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.Test;
Expand Down Expand Up @@ -3110,6 +3111,18 @@ public void generatesIdForInsertAll() {
assertThat(jesse.getId()).isNotNull();
}

@Test // GH-4944
public void insertAllShouldConvertIdToTargetTypeBeforeSave() {

RawStringId walter = new RawStringId();
walter.value = "walter";

RawStringId returned = template.insertAll(List.of(walter)).iterator().next();
org.bson.Document document = template.execute(RawStringId.class, collection -> collection.find().first());

assertThat(returned.id).isEqualTo(document.get("_id"));
}

@Test // DATAMONGO-1208
public void takesSortIntoAccountWhenStreaming() {

Expand Down