I need to ask a question about a nested object state in my document, which looks like this:
{
"_id" : ObjectId("5437248f2dfbc82fcafa9733"),
"_class" : "conference.Speaker",
"speakerId" : NumberLong(0),
"name" : "John Doe",
"talks" : [{
"talkId" : NumberLong(0),
"when" : ISODate("2014-10-17T15:00:00Z"),
"title" : "Stuff"
}]
}
This document looks fine and it is generated out of 2 classes, Speaker and Talk, when none of them have any annotations and the former has a List of the laters as a property.
What I need to get is a list of talks with certain name. Here's what I am tring to do:
BasicQuery query = new BasicQuery("{'talks.title' : 'Stuff'}");
This fails with org.springframework.data.mapping.model.MappingException: Invalid path reference talks.title! Associations can only be pointed to directly or via their id property!
I guess it can't use the Id property (since Talk object doesn't have it's own id), and I have no idea what 'can be pointed directly means'.
What's wrong with my query and/or the mapping?
talks.index.title(index = 0, 1, ...) - of course this style is out of your expectation. Another way is:Query query = new Query().addCriteria(Criteria.where("talks.title").is("Stuff"));. Not sure if it's what you want.