title: NodeJS - Mongoose (Object has no method "id")
body: <p>When I try this code in my Application:</p>
  
  <p><em>app/models/Post.coffee</em></p>
  
  <pre><code>mongoose      = require "mongoose"
  CommentModel  = require "./Comment"
  Comment       = CommentModel.Schema
  Schema        = mongoose.Schema
  
  Post = new Schema {
      title: String,
      slug: {type: String, index: { unique: true, dropDubs: true }},
      content: String,
      author: String,
      tags: [String],
      comments: [Comment],
      created: { type: Date, default: Date.now }
  }
  
  Post.statics.findBySlug = (slug, cb) -&gt;
      this.model("Post").findOne({ slug: slug }, cb)
  
  PostModel = mongoose.model "Post", Post
  
  module.exports = PostModel
  </code></pre>
  
  <p><em>app/models/Comment.coffee</em></p>
  
  <pre><code>mongoose  = require("mongoose")
  Schema    = mongoose.Schema
  
  Comment = new Schema {
      author: String,
      content: String,
      approved: Boolean,
      created: { type: Date, default: Date.now }
  }
  
  
  CommentModel = mongoose.model "Comment", Comment
  
  module.exports = CommentModel
  </code></pre>
  
  <p><em>app/controllers/PostsController.coffee</em> (Just one method)</p>
  
  <pre><code>commentDestroy: (req, res, next) -&gt;
      Post.findBySlug req.params.slug, (err, doc) -&gt;
          if (err)
              return next err
  
          if doc == null
              res.send 404
              return
  
          doc.comments.id(req.params.comment).remove()
          doc.save (err) -&gt;
              if err
                  next err
  
              res.json doc
  </code></pre>
  
  <p>It ends with error:</p>
  
  <pre><code>TypeError: Object [object Object],[object Object],[object Object],[object Object],[object Object] has no method 'id'
      at Promise.PostsController.commentDestroy (/home/r41ngoloss/Projects/www/my-express/app/controllers/PostsController.js:88:22)
      at Promise.addBack (/home/r41ngoloss/Projects/www/my-express/node_modules/mongoose/lib/promise.js:128:8)
      at Promise.EventEmitter.emit (events.js:96:17)
      at Promise.emit (/home/r41ngoloss/Projects/www/my-express/node_modules/mongoose/lib/promise.js:66:38)
      at Promise.complete (/home/r41ngoloss/Projects/www/my-express/node_modules/mongoose/lib/promise.js:77:20)
      at Query.findOne (/home/r41ngoloss/Projects/www/my-express/node_modules/mongoose/lib/query.js:1533:15)
      at model.Document.init (/home/r41ngoloss/Projects/www/my-express/node_modules/mongoose/lib/document.js:229:11)
      at model.init (/home/r41ngoloss/Projects/www/my-express/node_modules/mongoose/lib/model.js:192:36)
      at Query.findOne (/home/r41ngoloss/Projects/www/my-express/node_modules/mongoose/lib/query.js:1531:12)
      at exports.tick (/home/r41ngoloss/Projects/www/my-express/node_modules/mongoose/lib/utils.js:408:16)
  </code></pre>
  
  <p>I already tried to find solution for my problem, but i found just <a href="https://stackoverflow.com/questions/7035092/how-to-update-embedded-document-in-mongoose%20%22this">this</a> and I think, that I have schemas in right order (By <em>require</em>).</p>
  
  <p>Thanks for every answer.</p>