title: node js mongo search
body: <p>i want search for an id in a subject model, the model has an array of teachers id as follows</p>
  
  <pre><code>var Classroom = require('./classroom');
  var Teacher = require('./teacher');
  var ClassSectionSchema = new Schema({
   title : String,
   teacher_id : [{type: Schema.Types.ObjectId, ref: 'Teacher'}]
  
  });
  </code></pre>
  
  <p>i want to search for every teacher before deleting it but if the teacher is connected in a class section i dont want to delete it, i tried the following</p>
  
  <pre><code>router.post('/delete',function(req,res){
  var teacher_id= req.body.selected;
  
  Class_section.findOne({teacher_id:teacher_id},function(err,subject){
      if(err){
          console.log(err);
          res.json({status:"error", message :"error occurred"});
          return;
      }else if(subject){
          res.json({status:"error", message:"teacher has class"});
          return;
      }else{
          Teacher.remove({_id:teacher_id},function(err){
              if(err){
                  console.log(err);
                  res.json({status:"error", message :"error occurred"});
                  return;
              }else{
                  res.json({status:"success",message: "teacher deleted"});
                  return;
              }
          })
      }
  })
  })
  </code></pre>
  
  <p>the previous code only works if the class section has one teacher id, but if it has two teacher in the array of teacher ids the teacher gets deleted</p>