spring - Spring data Mongodb using mongoOperations - 使用查询条件获取嵌套/嵌入数组文档
问题描述
**Using positional projection:**
Criteria elementMatchCriteria = Criteria.where("organizationInformation.users").elemMatch(Criteria.where("emailAddress").is("testuser1@test.com").and("password").is("test1@123" )); 查询查询 = Query.query(elementMatchCriteria); query.fields().position("organizationInformation.users", 1); 列出 customerInfo =mongoOperations.find(query, CustomerInformation.class);
i have tried this approach in my case have more than one match record found but using positional projection it always giving only one matching record..
please help me is there any way to get multiple matching records using positional or any criteria to get nested/embeded array documents.thanks in advance.
sample collection as below based emailaddresss and password i should get 2 records but it is always giving one record.
{ "_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" : "testuser1",
"emailAddress" : "testuser1@test.com",
"password" : "test1@123",
"userAccessType" : "IT"
},
{
"firstName" : "testuser2",
"emailAddress" : "testuser2@test.com",
"password" : "test2@123",
"userAccessType" : "user"
}
]
}
}
解决方案
推荐阅读
- android - PageList 中的 BoundaryCallback 永远不会被调用
- asp.net-core - 在 ASP.NET Core 2.1 中将 Neo4j 驱动程序实例放在哪里?
- javascript - 带有离屏输入标签的角度复选框
- java - 线程“主”java.lang.NoSuchMethodException 中的异常
- node.js - npm live-server 不会自动重新加载
- css - 我正在应用 flex 属性,但它不会扩展或收缩
- python - 我的脚本无法点击某个网格
- android - 我想知道如何获取选中的checkboxin android studio的信息
- elasticsearch - Elasticsearch 在大型索引中搜索大量字段
- android - 我应该如何从多个复选框选择中的 ArrayList 中删除未选择的元素?