title: Express.js & Mongoose: access Object attribute name by the request parameter
body: <p><strong>The Context</strong></p>
  
  <p>The problem is that I would like to access the attribute of an Object by the variable passed in the request made. A GET /modify/:var request is made to modify the attribute of a saved document in MongoDB. To know which attribute of the doc, converted to an Object when fetched, we would like to modify, we need the string passed in the :var.</p>
  
  <p><strong>The Route</strong></p>
  
  <pre><code> public modify(req: express.Request, res: express.Response, next: express.NextFunction)
    {
      Model.findOne({attr: true}, (err, result) =&gt; {
        if (err) {
          console.log(err);
        }
        else {
          let copy = result;
          copy.attr.one.(req.params.var) = false; // here
        }
      });
    }
  </code></pre>
  
  <p><strong>Update</strong></p>
  
  <p>After the answer of Paul, I edited my code and it is returning a 500 status code. I edited </p>
  
  <pre><code>router.put('/route/:var')
  
  public mock(req: express.Request, res: express.Response, next: express.NextFunction) {
        Model.findOne({attr: false}, (err, doc) =&gt; {
          doc.attr[req.params.var] = false;
          model.save((e) =&gt; {
          if (e){
          console.log(e);
          }
            res.send(doc);
          });
      });
  </code></pre>
  
  <p><strong>The Model Structure</strong></p>
  
  <pre><code>export interface Model extends mongoose.Document {
    attr: {
               one:   {value: Boolean},
               two:   {value: Boolean},
               three: {value: Boolean},
               four:  {value: Boolean},
             };
  
  }
  </code></pre>