Am trying to query on MongoDB collection which is like below
{
"_id" : ObjectId("55e9a8efc4fd0e172cbffcae"),
"type" : "b",
"name" : [
{
"name" : "XYZ",
"age" : "25",
"source" : [
{
"source" : "srcOne"
}
]
},
{
"name" : "ABC",
"age" : "19",
"source" : [
{
"source" : "srcTwo"
}
]
}
]
}
When am trying to query for name with XYZ and age with 19 its matching and giving the result which should not because name is matched with different object and age with different, how can i do a and query for the same object so that i matched exactly with complete Object. Below is the java code it gives me the result but i expect it shouln't
Document findDocument2=new Document();
Document findDocument3=new Document();
ArrayList<Document> a=new ArrayList<>();
findDocument2.append("name.name", "XYZ");
findDocument3.append("name.age", "19");
a.add(findDocument2);
a.add(findDocument3);
Document resDoc = mongoDatabase.getCollection("entity").find(Filters.and(findDocument2,findDocument3)).first();
System.out.println(">>>>>>>>>>>>>>>>>>>>>>>> "+resDoc);