title: retrieve jsonObject from Mongoose
body: <p>I am implementing server related API using NodeJs and MongoDB with mongoose Schema based model. So My previous question was <a href="https://stackoverflow.com/questions/42595860/nodejs-with-mongodb-jsonformat-issue">here</a></p>
  
  <pre><code>'use strict';
  
  
  mongoose = require('mongoose'),
  Task = mongoose.model('Tasks');
  
  exports.list_all_tasks = function(req, res) {
    Task.find({}, function(err, task) {
      if (err){
        res.send(err);
      }
      // console.log('Web Server started, waiting for connections...'+task);
      res.json(task);
    });
  };
  </code></pre>
  
  <p>When i run the server it returns the jsonArray like this,</p>
  
  <pre><code> [
    {
     "_id": "58ba4c9c03e10b16d140775f",
     "name": "Noorul ahamed",
     "__v": 0,
     "status": [
     "pending"
    ],
     "Created_date": "2017-03-04T05:11:56.590Z"
   },
   ....
   ...
   ...
  ]
  </code></pre>
  
  <p>here my doubt is,</p>
  
  <p>in that above code, task gives this kind of response. how do i get the every object in that task array? do i need to use for loop to get all object from that array? I am new to  NodeJs and MongoDB. I structured well server.Now I am stuck with this.? Help will be appreciated.</p>
  
  <p><strong>UPDATE</strong></p>
  
  <pre><code>    // var myOwnObject = new mongoose.Schema({ name: 'string', id: 'string',status:'string',createdDate:'String' });
      //      var myOwnObject = {};
  
      var dataArray;
      for (var i = 0; i &lt; task.length; i++) {
          var userObject = task[i];
          myOwnObject.name=userObject.name;
          myOwnObject.id=userObject._id;
          myOwnObject.status=userObject.status[0];
          myOwnObject.createdDate=userObject.Created_date;
          dataArray[i]=myOwnObject;
       }
      res.json(JSON.Stringify(dataArray));
  </code></pre>
  
  <p><strong>Error</strong></p>
  
  <p>events.js:161
        throw er; // Unhandled 'error' event
        ^</p>
  
  <blockquote>
    <p>TypeError: Cannot set property 'name' of undefined
        at /home/noorulhasan/todoListApi/api/controllers/todoListController.js:17:29
        at model.Query. (/home/noorulhasan/node_modules/mongoose/lib/model.js:3433:16)
        at /home/noorulhasan/node_modules/kareem/index.js:273:21
        at /home/noorulhasan/node_modules/kareem/index.js:127:16
        at _combinedTickCallback (internal/process/next_tick.js:67:7)
        at process._tickCallback (internal/process/next_tick.js:98:9)
    [nodemon] app crashed - waiting for file changes before starting...</p>
  </blockquote>
  
  <p><strong>UPDATE ERROR</strong>
  When i tried with myObject={}</p>
  
  <p>events.js:161
        throw er; // Unhandled 'error' event
        ^</p>
  
  <blockquote>
    <p>TypeError: Cannot set property '0' of undefined
        at /home/noorulhasan/todoListApi/api/controllers/todoListController.js:21:25
        at model.Query. (/home/noorulhasan/node_modules/mongoose/lib/model.js:3433:16)
        at /home/noorulhasan/node_modules/kareem/index.js:273:21
        at /home/noorulhasan/node_modules/kareem/index.js:127:16
        at _combinedTickCallback (internal/process/next_tick.js:67:7)
        at process._tickCallback (internal/process/next_tick.js:98:9)</p>
  </blockquote>
  
  <p><strong>UPDATE</strong></p>
  
  <p>I am getting this kind of output. how to get rid of '\' symbol.</p>
  
  <p><code>"[{\"name\":\"Ahamed\",\"id\":\"58bac0fc2cf0894f071e41c0\",\"createdDate\":\"2017-03-04T13:28:28.759Z\"}]</code></p>
  
  <p>I tried following way.</p>
  
  <pre><code>    var jsonData=JSON.stringify(dataArray);
      var updateJson = jsonData.replace('"\"', "");
      res.json(JSON.stringify(updateJson));
  </code></pre>
  
  <p>but it adds extra symbols like below,</p>
  
  <p><code>"\"[{\\\"name\\\":\\\"Ahamed\\\",\\\"id\\\":\\\"58bac0fc2cf0894f071e41c0\\\",\\\"status\\\":\\\"pending\\\",\\\"createdDate\\\":\\\"2017-03-04T13:28:28.759Z\\\"}]\""</code></p>