Skip to content

Commit

Permalink
hotfix : mongoDB atlas로 변경
Browse files Browse the repository at this point in the history
  • Loading branch information
genius00hwan committed Nov 27, 2024
1 parent 6c73e2c commit 035036a
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 10 deletions.
2 changes: 1 addition & 1 deletion config
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ public Curriculum getCurriculum(
) {
CurriculumDecider decider = convertToDecider(majorType, departmentName, joinYear);


return repository.findByDecider(decider)
.orElseThrow(() -> new GeneralException(ErrorStatus.CURRICULUM_NOT_FOUND));
}
Expand Down
24 changes: 15 additions & 9 deletions src/main/java/icurriculum/global/config/SSHMongoConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -38,33 +38,39 @@ public class SSHMongoConfig {
@Value("${spring.data.mongodb.database}")
private String databaseName;

@Value("${spring.data.mongodb.connection_string}")
private String connectionCommand;

@Value("${spring.data.mongodb.app_name")
private String appName;

@Bean
public MongoClient mongoClient() {
String host = databaseEndpoint;
int port = databasePort;

// if (isServer.equals("false")) {
log.info("isServer value: {}", isServer);
Integer forwardedPort = initializer.buildSshConnection(databaseEndpoint, databasePort);
host = "localhost";
port = forwardedPort;
// log.info("isServer value: {}", isServer);
// Integer forwardedPort = initializer.buildSshConnection(databaseEndpoint, databasePort);
// host = "localhost";
// port = forwardedPort;
// }

try {
ConnectionString connectionString = new ConnectionString(String.format(
"mongodb://%s:%s@%s:%s/%s?readPreference=secondaryPreferred&retryWrites=false",
connectionCommand,
mongoUser,
mongoPassword,
host,
port,
databaseName
databaseEndpoint,
databaseName,
appName
));

MongoClientSettings mongoClientSettings = MongoClientSettings.builder()
.applyConnectionString(connectionString)
.build();

log.info("mongo connection through SSH: host={}, port={}", host, port);
log.info("mongo connection through SVG: end_point={}", databaseEndpoint);

return MongoClients.create(mongoClientSettings);
} catch (Exception e) {
Expand Down

0 comments on commit 035036a

Please sign in to comment.