I would like to update the factory’s status only if the size of (developers + testers) equal or greater than workers size, is this possible using mongoOperations ? if so I believe I need to use aggregations right ? because according to this doc, aggregations are used only to sort data (I’m not familiare with them).
Can you please provide a bunch of example docs that I can insert easily and the expected updates on these documents once your query is done? This would help figure out what you are trying to do exactly and what’s the best approach before trying to find a solution for the Spring Boot part. Let’s find the MongoDB query first and then we can try to “translate it” in Java / Spring Boot eventually.
And what I would like once, I add an element inside the array “testers” (for example), with mongo will compare the length of (developers + testers) with workers, and if it’s equal, mongo change the status to “FULL”, so the final result will be :
So the operation will be a mix of (findAndModify (to find the doc and add the element to an array) + comparaison of arrays size, then update the status if the the condition is met.
Which would work better if the status field was indexed.
This query would also be faster if the array sizes were stored (and indexed) instead of being re-calculated all the time.
It’s usually fairly easy to maintain the size of the array and the array in sync by using in the same update operation $push or $pop for the array and $inc for the size.
I have problem finding the added value in Spring Boot to be honest.
I did my own little starter project for people who are starting a project with Spring Boot here. But in my opinion it makes things more complicated than just using the MongoDB Java Driver…
I like the fact that interfaces are auto implemented… But in real life, you never use the CRUD APIs out of the box like this. You do custom queries like this one and it doesn’t make you save time. In the end you have an extra proxy between you and the MongoDB Driver (which is still used in the backstage) so…
Yeah, I’m not a fan. But a solid demo could as well change my mind perhaps.
I feel the same. That why I call them, this and mongoose, obstruction layer rather than abstraction layer.
One of the selling point of mongo is that they do not impose a schema. You could, but that would be another obstruction layer. For the same reason, I do not use query builders in Java. With my query in native json, I can have the same query, sometimes stored in a file, be used in all nodejs, mongosh, java, … with the help of parse().