0
**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"
                    }
                ]
            }
}
Rajasekhar
  • 1
  • 1
  • 2
  • You have to use aggregate query. Use $filter. Possible dupe of https://stackoverflow.com/q/46767750/2683814 – s7vr Aug 03 '18 at 03:42
  • thanks veeram for ur reply..just want to understand how can i apply for above collection.Aggregation aggregation = newAggregation( project().and(filter("parts") .as("item") .by(valueOf( "item.currentState") .equalToValue( "Estimation Confirmed"))) .as("parts"); ); – Rajasekhar Aug 03 '18 at 07:19

0 Answers0