Problem applying $unset and $pull operations on nested entities
See original GitHub issueDescribe the bug
We have queries doing various field operations on embedded objects in our system. Until now we have been using Morphia 1.5 without any issues. But we are currently migrating our system to Morphia 2.2.9 and encountered some problems, mainly with the $unset
and $pull
operators where they are not translated to their full paths (e.g. “parent.field”).
To Reproduce Lets say we have following Morphia query:
Query<CWOrg> query = ds.find(Entity.class).filter(eq("_id", someId));
query
.update(
UpdateOperators.unset("subscriptionDetails.syncAttempts"),
UpdateOperators.set("subscriptionDetails.lastSyncDate", syncDate))
.execute(new UpdateOptions().multi(true));
Morphia will translate the full path for the $set
operator but only use the mapped field name for the $unset
operator (found similar issues with $pull
). So logging the native Mongo query results in below update. This means that only the $set
operator applies as the $unset
has incorrect path.
[
{
"q": {"_id": {"$oid": "637b48c5735ce247d5759634"}
"u": {
"$unset": {"syncAttempts": ""},
"$set": {"subscriptionDetails.lastSyncDate": {"$date": "2022-11-21T09:45:41.514Z"}}
},
"multi": true
}
]
Expected behavior We would have expected that all operators are applied using their complete dot-notated path. But maybe we are misunderstanding something with the new APIs.
** Please complete the following information: **
- Server Version: 4.2
- Driver Version: 4.7
- Morphia Version: 2.2.9
Issue Analytics
- State:
- Created 10 months ago
- Reactions:1
- Comments:8 (3 by maintainers)
OK. Confirmed and fixed both failures. After several attempts, I finally found a way to directly those in bulk and in various combos. It’s not pretty but gets the job done. I’ll try to push 2.2.10 tomorrow.
I will try to take a look at this tonight/tomorrow. I was on the verge of push 2.2.10 and this would be good to get in before then.