title: Finding list of users and iterating over in Node/Mongoose
body: <p>Below in my code I am getting a list of users based on department. Than using that list I am using for loop to check if that user location is in the Loc table or not.  </p>
  
  <pre><code>user.find({dept: 'main'}, {}, (err, users)=&gt;{
    for(var i=0; i&lt;users.length; i++){
     var query={userid: users[i].userid};
      Loc.findOneAndUpdate({query, {$set: {locuser: user[i].locuser}}, {new: true, upsert: false}, (err, results)=&gt;{
      if(err) {  console.log(err)
      console.log("success")
    })
    }
  })
  </code></pre>
  
  <p>When I run this code it inserts last id repeatedly. Meaning if there were 4 users found it will insert 4 locations for the same one user who was last in the list while it should enter all 4 users.
  Please let me know how to fix this. Thanks </p>