Skip to content
Snippets Groups Projects
Commit b2ccae70 authored by Petr Ježek's avatar Petr Ježek
Browse files

mongodb connection setup, not working yet

parent b485c3a8
No related branches found
No related tags found
No related merge requests found
version: "3.1"
version: "3.8"
services:
database:
build:
context: ./database
image: atsea_db
environment:
POSTGRES_USER: gordonuser
POSTGRES_DB: atsea
mongodb:
container_name: mongodb
image : mongo
command:
- "--auth"
ports:
- "5432:5432"
networks:
- back-tier
secrets:
- postgres_password
appserver:
build:
context: .
dockerfile: app/Dockerfile-dev
image: atsea_app
ports:
- "8080:8080"
- "5005:5005"
networks:
- front-tier
- back-tier
secrets:
- postgres_password
secrets:
postgres_password:
file: ./devsecrets/postgres_password
networks:
front-tier:
back-tier:
payment:
driver: overlay
\ No newline at end of file
- "27017:27017"
restart: unless-stopped
\ No newline at end of file
......@@ -49,6 +49,11 @@
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
<version>2.5.5</version>
</dependency>
</dependencies>
<build>
......
package cz.cvut.fel.pro.emtt;
import cz.cvut.fel.pro.emtt.model.Question;
import cz.cvut.fel.pro.emtt.repository.QuestionRepository;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.CommandLineRunner;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.data.mongodb.core.query.Criteria;
import org.springframework.data.mongodb.core.query.Query;
import org.springframework.data.mongodb.repository.config.EnableMongoRepositories;
import java.util.List;
import java.util.Optional;
@SpringBootApplication
public class App {
@EnableMongoRepositories
@Slf4j
public class App implements CommandLineRunner {
@Autowired
QuestionRepository questionRepository;
public static void main(String[] args) {
SpringApplication.run(App.class, args);
}
@Override
public void run(String... args) throws Exception {
String title = "Epic question";
Question q = Question.builder().title("Epic question").text("This is something epic...").build();
questionRepository.insert(q);
List<Question> qs = questionRepository.findAll();
log.info(qs.toString());
}
}
package cz.cvut.fel.pro.emtt.model;
import lombok.Builder;
import lombok.Getter;
import org.springframework.data.mongodb.core.mapping.Document;
import javax.persistence.Id;
@Document
@Getter
@Builder
public class Question {
@Id
private String id;
private String title;
private String text;
}
package cz.cvut.fel.pro.emtt.repository;
import cz.cvut.fel.pro.emtt.model.Question;
import org.springframework.data.mongodb.repository.MongoRepository;
import org.springframework.data.mongodb.repository.Query;
public interface QuestionRepository extends MongoRepository<Question, String> {
@Query("{title:'?0'}")
Question findQuestionByTitle(String title);
}
spring.data.mongodb.uri=mongodb://admin:admin@localhost:27017/emtt
spring.autoconfigure.exclude=org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment