我的收藏如下:
{
"_id" : NumberLong(366),
"file" : "xyz",
"meta" : [{
"owner" : "user123",
"rating": "A"
}]
}
我想根据所有者
对查询结果进行排序我已尝试过以下代码,但排序无效
任何人都可以帮我这个。
query = new Query();
query.addCriteria(Criteria.where("meta.rating").is("A"));
query.with(new Sort(Sort.Direction.ASC, "meta.owner"));
mongoOperations.find(query, Test.class);
我的测试班: 这里我有List是另一个模型
@Document(collection = "Test_Data")
public class Test{
@Id
private long id;
private String file;
private List<MetaList> meta;
public long getId() {
return id;
}
public void setId(long id) {
this.id = id;
}
public String getFile() {
return file;
}
public void setFile(String file) {
this.file = file;
}
public List<MetaList> getMeta() {
return meta;
}
public void setMeta(List<MetaList> meta) {
this.meta= meta;
}
}
我的MetaList类:
public class MetaList{
private String owner;
private String rating;
public String getOwner() {
return owner;
}
public void setOwner(String owner) {
this.owner= owner;
}
public String getRating() {
return rating;
}
public void setRating(String rating) {
this.rating= rating;
}
}