我想使用mongorepository获取Id的值。下面的示例显示mondodb文档
{
"_id" : ObjectId("5baa4779f4a46b0f60a74313"),
"_class" : "hello.mytest",
"data" : {
"type" : [
{
"testId" : "Id0",
"usage" : "near",
"additionalProperties" : {}
},
{
"testId" : "Id1",
"usage" : "far",
"additionalProperties" : {}
}]}
}
当我尝试找到testId获得空值时。
public interface TestRepository extends MongoRepository<mytest, String> {
List<data> findBytestId(String string);
}
答案 0 :(得分:0)
findBytestId =>“ testId”必须为“ TestId”
public interface TestRepository extends MongoRepository<mytest, String> {
List<data> findByTestId(String testId);
}
答案 1 :(得分:0)
只需在方法中添加注释:
public interface TestRepository extends MongoRepository<mytest, String> {
@Query("{'data.type.testId': ?0}")
List<data> findBytestId(String string);
}