title: Convert a String to Object (json) MongoDB shell
body: <p>I am trying to execute the below command</p>
  
  <pre><code>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 }
  
      ])
  }
  </code></pre>
  
  <p>if I pass the below value for the field it works fine. </p>
  
  <pre><code>var field1 = {"events.concessionDetails":{$exists:true}};
  </code></pre>
  
  <p>But I dont want to pass the <code>'{$exists:true}'</code> and just want to pass <code>events.concessionDetails</code> and form the full command, Below is some code which I would like to execute to accomplish this task.</p>
  
  <p>I tried the following with no success,</p>
  
  <p>tojson(field)
  tojsonObject(field)
  eval(field)</p>
  
  <p>Is there any way that we can use to convert a input string to json query to use it in query.</p>