I have a dynamic schema on mongodb for different workflow templates. Each workflow template has data attributes associated which is stored as normal <key,value>
{
_id : “1”
data : {
team_id : “ABC”,
template_id : “retail_sales”,
recorded_at : “”,
billing_state : “KA”,
pin_code : “50001”
}
}
{
_id : 2
data : {
team_id : "ABC",
template_id : "simple_crm",
recorded_at : "",
status : "NEW",
loan_amount : 10000
}
}
I understand that with 4.2 there is a wildcard index which I wanted to use for aggregate queries. The have created a full document wildcard index as below
{
“$data.**” : 1
}
On executing the query I can see that the index is used.
db.getCollection(“view_status_dashboard”).aggregate(
[
{
“$match” : {
“data.team_id” : “ABC”,
“data.template_id” : “retail_sales”
}
}
},
{
$project : {
_id : 0,
data: 1
}
}
])
However the projection is making a “FETCH” call which increases the memory.