I am trying to execute the below command
function(field) {
//field = '{"'+field+'":{$exists:true}}'; Not working
//field = tojson(field) Not working
//field = {"events.concessionDetails":{$exists:true}}; Works if passed as input param
print(field);
var cur = db.cssCases.aggregate([
{$match:{"events.eventType" : {$nin:["FAIL_SYSTEM_SERVICE_CALL"]}}},
{ $unwind: "$events" },
{$match:field},
{$group:{_id:{eventType:"$events.eventType"}}},
{ $limit : 100 }
])
}
if I pass the below value for the field it works fine.
var field1 = {"events.concessionDetails":{$exists:true}};
But I dont want to pass the '{$exists:true}'
and just want to pass events.concessionDetails
and form the full command, Below is some code which I would like to execute to accomplish this task.
I tried the following with no success,
tojson(field) tojsonObject(field) eval(field)
Is there any way that we can use to convert a input string to json query to use it in query.