mirror of
https://github.com/OtusTeam/Spring.git
synced 2026-05-30 10:50:42 +00:00
mongo-db-example updated
This commit is contained in:
@@ -25,6 +25,7 @@
|
||||
<gson.version>2.10.1</gson.version>
|
||||
<snakeyaml.version>2.0</snakeyaml.version>
|
||||
<guava.version>32.0.0-jre</guava.version>
|
||||
<spring.shell.version>3.0.3</spring.shell.version>
|
||||
</properties>
|
||||
|
||||
<dependencies>
|
||||
@@ -34,6 +35,12 @@
|
||||
<artifactId>spring-boot-starter-data-mongodb</artifactId>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.springframework.shell</groupId>
|
||||
<artifactId>spring-shell-starter</artifactId>
|
||||
<version>${spring.shell.version}</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.yaml</groupId>
|
||||
<artifactId>snakeyaml</artifactId>
|
||||
|
||||
@@ -0,0 +1,2 @@
|
||||
1695056720328:m
|
||||
1695056755656:exit
|
||||
+50
@@ -0,0 +1,50 @@
|
||||
package ru.otus.example.mongodbdemo.commands;
|
||||
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.val;
|
||||
import org.bson.Document;
|
||||
import org.springframework.shell.standard.ShellComponent;
|
||||
import org.springframework.shell.standard.ShellMethod;
|
||||
import ru.otus.example.mongodbdemo.repositories.StudentRepository;
|
||||
import ru.otus.example.mongodbdemo.utils.RawResultPrinter;
|
||||
|
||||
@RequiredArgsConstructor
|
||||
@ShellComponent
|
||||
public class AppCommands {
|
||||
|
||||
private final StudentRepository studentRepository;
|
||||
private final RawResultPrinter rawResultPrinter;
|
||||
|
||||
@ShellMethod(value = "ShowLookupMagic", key = "m")
|
||||
public void showLookupMagic(){
|
||||
val student = studentRepository.findAll().get(0);
|
||||
for (int i = 0; i <= 7; i++) {
|
||||
val rawResults = studentRepository.getStudentExperienceByIdAggregationRawResultForStage(
|
||||
student.getId(), i);
|
||||
printStageDesc(i, rawResults);
|
||||
}
|
||||
}
|
||||
|
||||
private void printStageDesc(int stageNum, Document stageRawResults) {
|
||||
String[] operationsAsStr = new String[]{
|
||||
"match(Criteria.where(\"id\").is(studentId)",
|
||||
"unwind(\"experience\")"
|
||||
, "project().andExclude(\"_id\").and(valueOfToArray(\"experience\")).as(\"experience_map\")"
|
||||
, "project().and(\"experience_map\").arrayElementAt(1).as(\"experience_id_map\")"
|
||||
, "project().and(\"experience_id_map.v\").as(\"experience_id\")"
|
||||
, "lookup(\"knowledge\", \"experience_id\", \"_id\", \"experience\")"
|
||||
, "unwind(\"experience\")"
|
||||
, "project().and(\"experience._id\").as(\"_id\").and(\"experience.name\").as(\"name\")"
|
||||
};
|
||||
|
||||
System.out.printf("Stage: %d\n\n", stageNum);
|
||||
for (int j = 0; j <= stageNum; j++) {
|
||||
System.out.println(operationsAsStr[j]);
|
||||
}
|
||||
System.out.println();
|
||||
rawResultPrinter.prettyPrintRawResult(stageRawResults);
|
||||
System.out.println("\n");
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -5,9 +5,19 @@ spring:
|
||||
port: 27017
|
||||
database: awesomeMongo
|
||||
|
||||
shell:
|
||||
interactive:
|
||||
enabled: true
|
||||
noninteractive:
|
||||
enabled: false
|
||||
|
||||
command:
|
||||
version:
|
||||
enabled: false
|
||||
|
||||
mongock:
|
||||
runner-type: "ApplicationRunner" # default
|
||||
#runner-type: "InitializingBean"
|
||||
#runner-type: "ApplicationRunner" # default
|
||||
runner-type: "InitializingBean"
|
||||
change-logs-scan-package:
|
||||
- ru.otus.example.mongodbdemo.changelogs
|
||||
mongo-db:
|
||||
|
||||
@@ -7,6 +7,15 @@ spring:
|
||||
#port: 27017
|
||||
#database: awesomeMongo
|
||||
|
||||
shell:
|
||||
interactive:
|
||||
enabled: true
|
||||
noninteractive:
|
||||
enabled: false
|
||||
|
||||
command:
|
||||
version:
|
||||
enabled: false
|
||||
de:
|
||||
flapdoodle:
|
||||
mongodb:
|
||||
|
||||
Reference in New Issue
Block a user