1) Problem Description:
- I am using a Reactive Spring-Data + Spring WebFlux + MongoDb + ReactiveMongoTemplate;
- I have 02 Collections: Task and Project
2) My Goal is:
- Using only “one update method”
- that updates the 02 documents inside the 02 Collections (at the same time - simultaneously)
3) Code:
3.1) Collection Task
@Document(collection = "task")
public class Task {
@Id
private String _id;
@Field("pid")
private String projectId;
private String taskName;
private String ownerProject;
}
3.2) Collection Project
@Document(collection = "project")
public class Project {
@Id
private String _id;
private String ownerProject;
private Task tasksProject;
private String code;
}
3.3) My current code - which is not working
public Mono<Void> updateWithCriteriaTemplateMult(String id) {
Query projectDocument = new Query();
projectDocument.addCriteria(Criteria.where("_id")
.is(id));
Query taskDocument = new Query();
taskDocument.addCriteria(Criteria.where("projectId")
.is(id));
return template
.update(projectDocument, Project.class)
.then(template.update(taskDocument, Task.class))
;
}
2) Question:
How Can I code/do “the same UPDATE-METHOD” updates both Collections “at the same time” using ReactiveMongoTemplate?
- Example 01: My method needs to “update” the field “ownerProject” in both Collections:
- Task: in this case ‘ownerProject’ is a simple field
- Project: in this case ‘ownerProject’ is a simple field
- Example 01: My method needs to “update” the field “ownerProject” in both Collections:
Example 02:
- My method needs to “update” the field “taskName” in both Collections:
- Task: in this case ‘TaskName’ is a simple field
- Project: in this case ‘TaskName’ is field “inside” “tasksProject”
- My method needs to “update” the field “taskName” in both Collections:
Thanks a lot for any help