Skip to content

Update versions and account for new standards #1

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Jun 12, 2025
Merged
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
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,7 @@ Connects to a replica set and bulk inserts a number of random documents. Uses th
- Documents are sent to the products collection in a user defined database.


This is sample source provided as an example and is not supported in any way by MongoDB.
This sample application is provided to demonstrate integration capability. Users
should review this code for component versioning and overall applicability for
their own use case.

71 changes: 25 additions & 46 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,91 +5,70 @@
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.6.10</version>
<relativePath/> <!-- lookup parent from repository -->
<version>3.2.5</version>
<relativePath/> <!-- Lookup parent from repository -->
</parent>
<groupId>com.mongodb.examples</groupId>
<artifactId>SpringDataBulkInsert</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>SpringDataBulkInsert</name>
<description>SpringDataBulkInsert</description>
<properties>
<java.version>11</java.version>
<java.version>17</java.version>
</properties>
<dependencies>
<!-- Spring Boot Web Starter -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-mongodb</artifactId>
<version>2.7.2</version>
</dependency>

<dependency>
<groupId>org.mongodb</groupId>
<artifactId>bson</artifactId>
<version>4.0.6</version>
</dependency>

<dependency>
<groupId>org.mongodb</groupId>
<artifactId>mongodb-driver-sync</artifactId>
<version>4.0.6</version>
</dependency>

<dependency>
<groupId>org.mongodb</groupId>
<artifactId>mongodb-driver-core</artifactId>
<version>4.0.6</version>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>

<!-- Spring Data MongoDB -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-configuration-processor</artifactId>
<optional>true</optional>
<artifactId>spring-boot-starter-data-mongodb</artifactId>
</dependency>

<!-- Lombok (optional, for annotations like @Getter/@Setter) -->
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<optional>true</optional>
</dependency>

<!-- Testing -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
<exclusions>
<exclusion>
<groupId>org.junit.vintage</groupId>
<artifactId>junit-vintage-engine</artifactId>
</exclusion>
</exclusions>
</dependency>

<dependency>
<groupId>io.github.hakky54</groupId>
<artifactId>sslcontext-kickstart</artifactId>
<version>7.4.5</version>
</dependency>

<dependency>
<groupId>com.github.javafaker</groupId>
<artifactId>javafaker</artifactId>
<version>1.0.2</version>
<groupId>net.datafaker</groupId>
<artifactId>datafaker</artifactId>
<version>2.4.3</version>
</dependency>

<!-- Security (optional) -->
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-validator</artifactId>
<version>7.0.4.Final</version>
<groupId>io.github.hakky54</groupId>
<artifactId>sslcontext-kickstart</artifactId>
<version>8.3.7</version>
</dependency>

</dependencies>

<build>
<plugins>
<!-- Spring Boot Maven Plugin -->
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<excludes>
<exclude>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
</exclude>
</excludes>
</configuration>
</plugin>
</plugins>
</build>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,12 @@ public class CustomProductsRepositoryImpl implements CustomProductsRepository {
private static final Logger LOG = LoggerFactory
.getLogger(CustomProductsRepository.class);

private final MongoTemplate mongoTemplate;

@Autowired
MongoTemplate mongoTemplate;
public CustomProductsRepositoryImpl(MongoTemplate mongoTemplate){
this.mongoTemplate = mongoTemplate;
}


public void updateProductQuantity(String name, int newQuantity) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,22 @@
import com.mongodb.MongoClientSettings;
import com.mongodb.client.MongoClient;
import com.mongodb.client.MongoClients;
import nl.altindag.ssl.SSLFactory;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.mongodb.core.MongoTemplate;

import javax.net.ssl.SSLContext;
import java.nio.file.Paths;
import nl.altindag.ssl.SSLFactory;

@Configuration
public class MongoConfig {
@Value("${mongodb.uri}")
private String uri;
@Value("${mongodb.database}")
private String databaseName;

@Value("${truststore.path}")
private String trustStorePath;
@Value("${truststore.pwd}")
Expand All @@ -35,7 +36,6 @@ public MongoClient mongo() {
MongoClientSettings mongoClientSettings = MongoClientSettings.builder()
.applyConnectionString(connectionString)
.applyToSslSettings(builder -> {

if (!atlas) {
// Use SSLContext if a trustStore has been provided
if (!trustStorePath.isEmpty()) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.mongodb.examples.springdatabulkinsert;

import com.github.javafaker.Faker;
import net.datafaker.Faker;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.data.annotation.Id;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,5 +29,6 @@ public void run(String... args) throws Exception {

repository.bulkInsertProducts(count);
LOG.info("End run");
System.exit(1);
}
}
4 changes: 1 addition & 3 deletions src/main/resources/application.properties
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@

mongodb.database=bulk

#mongodb.uri=mongodb://root:[email protected]:37017,m02.mdbkrb5.net:37017,m03.mdbkrb5.net:37017/admin?authMechanism=SCRAM-SHA-1&authSource=admin&tls=true

mongodb.uri=mongodb+srv://root:[email protected]/?retryWrites=true&w=majority
mongodb.uri=<connection string>
mongodb.atlas=1

truststore.path=/etc/ssl/truststore.jks
Expand Down