Here is what went wrong
var query = "\"info.name\": \"ABC\"";
{ $match: ""info.name": "ABC"" } // This is single string
Here in this query, we get single string that's why not result filter
But when you are using explicitly passing like this "info.name": "ABC" it work
For data
{
_id: ObjectId(XXXXXXXXXX),
info: { name: "ABC" }
}
You can use this aggregate query
// Create object and use this into [$match][1] stage
const data = { "info.name": "ABC" };
// Use this object in match stag
.aggregate([{ $match: data}])
if you have array of object then you need to use $elemMatch
For data
{
_id: ObjectId(XXXXXXXXXX)
info: [{ name: "ABC" }, { name: "DEF" } ]
}
// use elemMatch if array of object
.aggregate([{ $match: { info: { $elemMatch:{ name: "ABC" }}}}])