I have this:
- A field which is a map where the keys are UUIDs and the value another object which is not relevant.
- A list of UUIDs that should be passed as parameter.
I want to:
delete from the collection all documents where all keys of the map are included in the list of UUIDs
The object:
@Document
public class MyClass
{
private Map<UUID, anotherObject> myMap;
}
With derived queries I am not able to reach the UUID because has no name -> deleteByMyMap…
And with a query I know that there is a way to convert the map into an array ($expr and $objectToArray) but I do not know if it makes sense.
- Is there any way to do this?
- How can I access just the key of the map?
3
Answers
This could be also an answer:
Here the mongoplayground
The map to spring-data-mongodb:
try this it might help:
Get keys in a single document
You can also use aggregation to get keys in a single document:
to delete:
This is one way of doing it, use an aggregation pipeline to get
_id
of all documents matching your criteria:How it works:
Using these ids, you can simply do:
Playground for the aggregation.