I have a simple class Foobar that contains a list of Objects that have a name.
These are stored using DBRefs.
What i wanna do is search for Foobars where one of these objects name is something.
JSON of Foobar looks like this:
This does not work (of course)Code:{ "_id": ObjectId("4dc01b367064d7e9b6418e68"), "refs": [ { "$ref": "camelCaseClass", "$id": ObjectId("4dc01b367064d7e9b4418e68") }, { "$ref": "camelCaseClass", "$id": ObjectId("4dc01b367064d7e9b5418e68") } ] }
But this doesn't work as well:Code:Query query = new Query(); query.addCriteria(Criteria.where("refs.name").is("foo1")); System.out.println(query.getQueryObject().toString()); List<Foobar> find = template.find("foobar", query, Foobar.class);
(Doesn't work means i don't get the expected result, i get an empty list)Code:query.addCriteria(Criteria.where("refs.$id").is(foo1.getId()));
Is it even possible to query across documents using DBRefs?
Do i have to store them embedded if i want to be able to do so?
Thanks


Reply With Quote