title: search queries in nodejs and mongodb and populated data
body: <p>i have a web app that's written in nodejs and mongodb, i have the following two models</p>
  
  <pre><code>   var TeacherSchema = new Schema({
         school_id:[{type: Schema.Types.ObjectId, ref: 'School'}],
         name: String,
         subjects: [{type: Schema.Types.ObjectId, ref: 'Subject'}],
         });
  
  
   var SubjectSchema = new Schema({
       title : String,
       school_id:[{type: Schema.Types.ObjectId, ref: 'School'}]
       });
  </code></pre>
  
  <p>i wrote an api that searches throw the teacher or subjects</p>
  
  <pre><code> router.get("/field-teacher-subject", function (req, res) {
  var   school_id= req.query.schoolId;
  Subject.find(school_id:'school_id,function (err, subjects) {
      if (err) {
          console.log(err);
          res.json({status: "error", message: err.message});
      } else {
          var sub_array=[];
          for(var q in subjects){
              sub_array.push(subjects[q]._id);
          }
          Teacher.find({subjects:{$in :sub_array }},{first_name:true, father_name:true, last_name : true, subjects:true}).populate('subjects')
              .exec(function(tech) {
                  console.log("hello: ");
                  var subjeto = [];
                  if(tech){
                      for(var p in tech){
                          subjeto.push(tech[p].subjects);
                      }
                  }
                  res.json({status: "success", message: "subjects returned", 
              items: tech});
              }).catch(function(err){
                  if(err){
                      res.json({status:"error",
                        message:"error occurred"+err.message});
                      return;
                  }
              });
      }
  }).limit(parseInt(req.query.max));
  });
  </code></pre>
  
  <p>THIS RETURNS null when i search for a name,
  what is the best way to solve this</p>