**Using positional projection:**
Criteria elementMatchCriteria = Criteria.where("organizationInformation.users").elemMatch(Criteria.where("emailAddress").is("testuser1@test.com").and("password").is("test1@123")); Query query = Query.query(elementMatchCriteria); query.fields().position("organizationInformation.users", 1); List 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"
}
]
}
}