title: get by id in mongoose
body: <p>If I want to get by id a only subdocument that is an array into a document, how I need to call it? I have these models</p>
  
  
  
  <pre><code>/* Build */
  var buildSchema = new Schema({
    buildName: String,
    package: [packageSchema],
    postedBy: {
      type: mongoose.Schema.Types.ObjectId,
      ref: 'user'
    }
  })
  var Build = mongoose.model('build', buildSchema)
  
  /* Project */
  var projectSchema = new Schema({
    projectName: String,
    build: [buildSchema],
    postedBy: {
      type: mongoose.Schema.Types.ObjectId,
      ref: 'user'
    }
  })
  var Project = mongoose.model('project', projectSchema)
  </code></pre>
  
  <p>my get function and route is this:</p>
  
  <pre><code>router.get('/build/:id', function (req, res, next) {
    var token = helperJwt.decodeToken(req)
    jwt.verify(token, helperJwt.secret, function (error, decoded) {
      if (error) {
        res.status(401)
      } else {
        Project.findOne({ _id: req.params.id}, 'build', function (err, build) {
          if (err) {
            res.status(401)
          } else {
            build.findOne({build: build._id}, 'postedBy', 'email', function (err, getBuild) {
              if (err) {
                res.status(401)
              } else {
                return status(200).json(build)
              }
            })
          }
        })
      }
    })
  })
  </code></pre>
  
  <p>that is good or how can I do for get only one build?</p>
  
  <p>I'm using vue as front end but it doesn't recognise only one build data.</p>
  
  <p>I don't know how to findById a subdocument.</p>
  
  <p>I want to bring something like:</p>
  
  <pre><code>{
      "_id" : ObjectId("5a26fbfd1866893baf14b175"),
      "postedBy" : "5a2021539f1d222bfc915fa2",
      "projectName" : "El pipiripau",
      "build" : [ 
          {
              "buildName" : "bdfbdgf",
              "postedBy" : ObjectId("5a2021539f1d222bfc915fa2"),
              "_id" : ObjectId("5a26fc0dbe4de0039cdae0c7"),
              "package" : []
          }, 
  }
  </code></pre>