failed because of dotted notation comp_users.dg_user in array filter. I tryed to use instead of dotted notation comp_users.$.dg_use as suggested still getting failure. Any suggestion on what I am doing wrong , appreciated
I do not use builder classes because of the extra knowledge you need to have to use them.
I do not use builder classes because I use mongosh extensively and JS and I like my queries and aggregations to be syntactically closed in each language. Builders are an extra layers that I avoid.
For this what I proposed do not use builders, but straight org.bson.Document in a way that is easier for me to use.
I start with the equivalent of {$regex: /^DWM/i}*
that is easier to map into Java. The equivalent is { $regex: "^DWM" , $options : "i" }.
I also use the equivalent {"dg_mid":"ff4c4ff6-6492-4326-8a41-9a0272c7c265"}
rather than {"dg_mid": {"$eq": "ff4c4ff6-6492-4326-8a41-9a0272c7c265"}}.
Here it is (n.b. I have not tried to compile or test it):
query = new Document( "dg_mid" ,
"ff4c4ff6-6492-4326-8a41-9a0272c7c265" ) ;
update = new Document( "$pull" :
new Document( "comp_users" :
new Document( "db_users" :
new Document( "$regex" : "^DWM" ).append( "$options" , "i" ) ) ) ) ;
collection.updateOne( query , update ) ;
Alternatively but relatively slower, you should get the same result with: