title: nodejs app mongoose database where clause with join
body: <p>I have a schema article defined as: </p>
  
  <pre><code>var ArticleSchema = new Schema({
      title: String,
      content: String,
      creator: {
          type: Schema.ObjectId,
          ref: 'User'
      }
  })
  </code></pre>
  
  <p>And user schema: </p>
  
  <pre><code>var UserSchema = new Schema({
      type: String, //editor, admin, normal
  
      username: String,
      password: String,
  
  })
  </code></pre>
  
  <p>I need to query all the article created by editor, i.e. in sql language</p>
  
  <pre><code>select Article.title as title, Article.content as content
  from Article inner join User 
  on Article.creator = User._id 
  where User.type = 'editor'
  </code></pre>
  
  <p>This is what I have tried</p>
  
  <pre><code>exports.listArticle = function(req, res, next) {
      var creatorType = req.query.creatorType
      var criteria = {}
      if (creatorType)
          criteria = {'creator.type': creatorType}
      Article.find(criteria).populate('creator').exec(function(err, articles) {
          if (err)
              return next(err)
          //ok to send the array of mongoose model, will be stringified, each toJSON is called
          return res.json(articles)
      })
  }
  </code></pre>
  
  <p>The returned <code>articles</code> is an empty array <code>[]</code></p>
  
  <p>I also tried <code>Article.populate('creator').find(criteria)</code>, also not working with error: </p>
  
  <pre><code>utils.populate: invalid path. Expected string. Got typeof `undefined`
  </code></pre>