我要问一个问题,我的文档中嵌套对象的状态,这看起来是这样的:查询嵌套对象
{
"_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"
}]
}
这份文件看起来不错,它是产生了2班,Speaker
和Talk
,当他们都没有任何注释,前者有一个名单作为属性。
我需要得到的是具有特定名称的会谈清单。 这里是我特林做:
BasicQuery query = new BasicQuery("{'talks.title' : 'Stuff'}");
这种失败org.springframework.data.mapping.model.MappingException: Invalid path reference talks.title! Associations can only be pointed to directly or via their id property!
我想这不能使用Id属性(因为谈话对象不具有它自己的ID),我有不知道'可以直接指出'是什么意思。
我的查询和/或映射有什么问题?
我想这是因为** **会谈是一个数组。直接指出,它应该是'talks.index.title'(index = 0,1,...) - 当然这种风格超出了你的期望。另一种方法是:Query query = new Query()。addCriteria(Criteria.where(“talks.title”)。is(“Stuff”));'。不知道这是你想要的。 – Wizard 2014-10-10 02:18:24