以下是我的两个课程:
@Document(collection="people")
public class Person {
// Data.
@Id
private ObjectId Id;
@Field("email")
private String email;
@DBRef
private List<Entity> entities;
/* Getters and setters removed to keep this question simple. */
}
而且,这是我的实体类。
@Document(collection = "entities")
public class Entity {
@Id
private ObjectId Id;
@DBRef
private List<Person> people;
/* Getters and setters removed to keep question simple. */
}
这是我的mongoRepository:
public interface EntityRepository extends MongoRepository<Entity, String>{
List<Entity> findByPeople_email(String email);
}
我想你可以看到我想在这里做什么 - 我想查询mongo数据库,并找回附加到用户的所有实体,其中电子邮件地址与我提供的地址相匹配。我一直陷入SQL思维模式,并且认为我可以做类似的事情:
SELECT * FROM people WHERE email="<email_here>"
但显然事实并非如此!谁知道我错过了什么?