我在 mongo 集合中有一个名为 (CustomerInformation) 的文档,其结构如下。
{ "_id" : ObjectId("58f5e68c8205281d68bbb290"),
"_class" : "com.test.dataservices.entity.CustomerInformation",
"organizationInformation" : {
"_id" : "123",
"companyName" : "Test1",
"ibanNumber" : "12345e",
"address" : "estates",
"contractInformation" : {
"duration" : NumberInt(0),
"contractType" : "Gold",
"totalUsers" : NumberInt(0)
},
"users" : [
{
"firstName" : "testuser1",
"emailAddress" : "testuser1@test.com",
"password" : "test1@123",
"userAccessType" : "admin"
},
{
"firstName" : "testuser2",
"emailAddress" : "testuser2@test.com",
"password" : "test2@123",
"userAccessType" : "user"
}
]
}
}
现在我只想检索具有匹配电子邮件地址和密码的用户信息。我正在尝试如下。
Criteria elementMatchCriteria = Criteria.where("organizationInformation.users").
elemMatch(Criteria.where("emailaddress").is("testuser1@test.com").and("password").is(test1@123));
BasicQuery query = new BasicQuery(elementMatchCriteria.getCriteriaObject());
CustomerInformation customer =mongoOperations.findOne(query, CustomerInformation.class);
我正在获取包含所有用户数组的完整文档,我只想检索匹配的用户信息 emailAddress 和密码。我的查询或数据模型有什么问题?有什么建议么?谢谢!