我们如何在Spring Data Mongo中选择特定的字段。我尝试了以下,但我得到了从Foo
到String
的投射异常。如何在Spring Data MongoDB中仅返回查询的特定字段?
使用@Query
@Query(value="{path : ?0}", fields="{path : 0}")
String findPathByPath(String path);
非@Query
String findPathByPath(String path);
这里是文档模型
@Document(collection = "foo")
public class Foo {
String name, path;
…
}
更多信息,你在说什么? MongoDB没有列。 – chrylis
我只想从我的模型中返回特定的字段。 在sql中它相当于 SELECT路径FROM foo – richersoon