title: Insertion issue in Json Array object mongodb with Nodejs?
body: <p>I am new to mongodb , I have below Json structure in mongodb ,</p>
  
  <pre><code>{
      "_id" : ObjectId("59d62452a164b51d64b714c2"),
      "folderName" : "Avinash 1234",
      "tag" : "search",
      "ismainFolder" : true,
      "innerFolder" : [ 
          {
              "ismainFolder" : false,
              "foldername" : "Test12",
              "_id" : ObjectId("59d72246e66adf2cfcfdd6e6")
          }
      ],
      "innerFiles" : [ 
          {
              "filelocation" : "",
              "isFolder" : false,
              "filename" : "Penguins.jpg",
              "_id" : ObjectId("59d7223de66adf2cfcfdd6e5")
          }, 
          {
              "filelocation" : "",
              "isFolder" : false,
              "filename" : "Desert.jpg",
              "_id" : ObjectId("59d72ff4e66adf2cfcfdd6ec")
          }, 
          {
              "filelocation" : "",
              "isFolder" : false,
              "filename" : "Hydrangeas.jpg",
              "_id" : ObjectId("59d731dfe66adf2cfcfdd6ed")
          }, 
          {
              "filelocation" : "",
              "isFolder" : false,
              "filename" : "Chrysanthemum.jpg",
              "_id" : ObjectId("59d73252e66adf2cfcfdd6ee")
          }
  
      ],
      "__v" : 0
  }
  </code></pre>
  
  <p>For innerFiles array i need to insert the Tag field depending on the id ("_id" : ObjectId("59d7223de66adf2cfcfdd6e5")) . I used following nodeJs code but it adding as a new object . Please give me the solution .</p>
  
  <pre><code>exports.addTagForSearch = function (req, res, next) {
      var tagDetails = req.body.tagDetails;
      console.log("tagDetails", tagDetails);
      console.log("tagDetails", tagDetails._id);
      Repository.find({ _id: tagDetails._id, }, { innerFiles: { $elemMatch: { _id: tagDetails._id } } },function (err, response) {
          $push: {
                  innerFiles: {
                      "tagName": tagDetails.tagname,
                      }
              //"filelocation": tagDetails.filelocation
          }
  
      }, { upsert: true, new: true }, function (err, post) {
          if (err) return next(err);
          return res.status(200).json("success");
      });
  }
  </code></pre>
  
  <p>but above code inserting as a new object , Please give me solution please .  </p>