title: Iterating Over an Array and Returning First Match from MongoDB using Mongoose
body: <p>I have a collection of <code>Users</code> in my database with corresponding unique <code>ids</code>. I am writing a function that takes an array of ids as an argument, e.g:
  <code>[&quot;user_id1&quot;, &quot;user_id2&quot;, &quot;user_id3&quot;, &quot;user_id4&quot;]</code>.</p>
  <p>I want my query to return the first and only the first match. i.e. Using the example above, if <code>user_id2</code> and <code>user_id4</code> were the only two matching users in the database, my result would only return <code>user_id2</code>. User ids that are not in the database are ignored.</p>
  <p>My current approach is to use a while loop, but I wanted to see if there was a better solution provided by Mongoose.</p>
  <p>Current Pseudo Code:</p>
  <pre><code>function findOneUser(userIdArr) {
      let user = 0;
      let returnedUser;
      while(!returnedUser || user &lt; userIdArr.length) {
          let id = userIdArr[user];
          user = await User.findByID(id);
          user++;
      }
  }
  </code></pre>