title: Mongoose running a Get on a nested array
body: <p>So Currently the setup I have shows all the results from the users which is great but I only want to get the array called visits which the users hold. </p>
  
  <p>This is how I have it set up so far: </p>
  
  <pre><code>getClicks() {
      this.http
        .get&lt;{ message: string; users: any }&gt;(
          BACKEND_URL_Analytics + '/user-clicks'
        )
        .pipe(
          map(data =&gt; {
            return data.users.map(user =&gt; {
              console.log(user);
              return {
                _id: user._id,
            *** visits: [user.visitCount] ****
              };
            });
          })
        )
        .subscribe(
          result =&gt; {
            this.userAnalytics = result;
            this.userAnalyticsUpdate.next([...this.userAnalytics]);
          },
          error =&gt; {
            console.log(error);
          }
        );
   }
  </code></pre>
  
  <p>These is my database structure: </p>
  
  <pre><code>const mongoose = require('mongoose');
  const uniqueVal = require('mongoose-unique-validator');
  const Schema = mongoose.Schema;
  
  const visitsSchema = new Schema ({
    postId: {
      type: String
    },
    visitCount: {
      type: Number,
      default: 1
    }
  })
  
  const userSchema = mongoose.Schema({
    email: {
      type: String,
      required: true,
      unique: true
    },
    password: {
      type: String,
      required: true
    },
    role: {
      type: String,
      required: true
    },
    answers: {
      type: String
    },
    visits: [visitsSchema]
  });
  
  userSchema.plugin(uniqueVal);
  
  module.exports = mongoose.model('User', userSchema);
  </code></pre>
  
  <p>My aim is to get the user Id which is automatically created by mongoose, as _ID which is fairly easy to do. But then I need to access the <code>visits: [visitsSchema]</code>.</p>
  
  <p>This is the console.log result from <code>console.log(user);</code> : </p>
  
  <pre><code>{_id: "5b3f839e6633e59b673b4a4e", email: "admin@hotmail.com", password: "$2b$10$IJ71o/SSfRDoQY4r./gKaetstvka8fFhh4tk35BUD4ReXaKhw1OrC", role: "admin", visits: Array(2), …}
  email:"admin@hotmail.com"
  password:"$2b$10$IJ71o/SSfRDoQY4r./gKaetstvka8fFhh4tk35BUD4ReXaKhw1OrC"
  role:"admin"
  visits:Array(2)
  0:{visitCount: 3, _id: "5b7c32015f015d5108002e88", postId: "5b5dbba4c67aad56df79f341"}
  1:{visitCount: 1, _id: "5b7c32f72f457a517aaef23b", postId: "5b688fb0e90f608916e7548b"}
  </code></pre>
  
  <p>The visits array shown in the console.log contains the <code>visitCount</code> and the <code>postID</code> which I need to recover and send to the frontend. Any advice on how I can fix the map or the return values in order to get the right information. If getting the ID is too hard then I would accept just getting the <code>visitCount</code> and <code>postID</code>, So I can add that to a table and display it, thanks!</p>
  
  <pre><code>{
      "message": "Activities were fetched succesfully!",
      "users": [
          {
              "visits": [],
              "_id": "5b3f84246633e59b673b4a50",
              "email": "teacher@hotmail.com",
              "password": "$2b$10$AZad.DdvPYHS4ttkLkQMyeA5wwe49JoSuJ4DvTO8xdp13gIlmF2Xy",
              "role": "teacher",
              "__v": 0
          },
          {
              "_id": "5b3f839e6633e59b673b4a4e",
              "email": "admin@hotmail.com",
              "password": "$2b$10$IJ71o/SSfRDoQY4r./gKaetstvka8fFhh4tk35BUD4ReXaKhw1OrC",
              "role": "admin",
              "visits": [
                  {
                      "visitCount": 3,
                      "_id": "5b7c32015f015d5108002e88",
                      "postId": "5b5dbba4c67aad56df79f341"
                  },
                  {
                      "visitCount": 1,
                      "_id": "5b7c32f72f457a517aaef23b",
                      "postId": "5b688fb0e90f608916e7548b"
                  }
              ],
              "__v": 0
         },
  </code></pre>
  
  <p>Ontop is my postman request from the backend maybe this helps? Thanks</p>