I've a complex collection in MongoDB. In this, I want to query departments data based on the subDeptName. I used query like below db.getCollection('users').find({"departments.subDeptName" : "Java"}), but its fetching all the array elements of the department. I only wants to query such department where "subDeptName" : "Java". How can we do that ?
{
    "firstName" : "John",
    "lastName" : "Kerr",
    "email" : "john.kerr@gmail.com",
    "countryName" : "USA",
    "usRestrictionSw" : "N",
    "status" : "Active",
    "effDate" : ISODate("2012-08-24T01:46:33.000Z"),
    "departments" : [ 
        {
            "subDeptCd" : "AB",
            "languageCd" : "en",
            "desc" : "Development Group",
            "subDeptName" : "Java",
            "status" : "Active"
        }, 
        {
            "subDivisionAlpha2Cd" : "KG",
            "subDivisionCd" : "B",
            "languageCd" : "ru",
            "desc" : "Testing Group",
            "subDeptName" : "Python",
            "status" : "Active"
        }, 
        ..........
        ..........
        ..........
        ..........
    }
}
 
     
    