Spring -Data / MongoDB / QueryDSL Search for nested _id of ObjectId

When a document from a collection is embedded in a document of another collection, it is pretty standard to make a copy of the attached document verbatim, rather than creating another type of document just for nesting. Example:

category {"_id": ObjectId("c1"), "name": "Category 1"}
question {"_id": ObjectId("q1"), category: {"_id": ObjectId("c1"), "name": "Category 1"}}

When using queryDSL as follows:

question.category.id = "c1"

queryDSL generates the following query:

"question.category._id":"c1"

where i expect:

"question.category._id":ObjectId("c1")

This works for top-level documents, not for nested ones. I think this is a valid case, and Spring should do the same translations as for top-level searches. Is there a workaround for this?

+4
source share

All Articles