title: Creating compound indexes that will match queries in MongoDB
body: <p>For our app I'm using the free-tier (for now) on MongoDB-Atlas.
  our documents have, among other fields, a start time which is a Datetime object, and a userId int.</p>
  
  <pre><code>export interface ITimer {
      id?: string,
      _id?: string, // id property assigned by mongo
      userId?: number,
      projectId?: number,
      description?: string,
      tags?: number[],
      isBillable?: boolean,
      isManual?: boolean,
      start?: Date,
      end?: Date,
      createdAt?: Date,
      updatedAt?: Date,
      createdBy?: number,
      updatedBy?: number
  };
  </code></pre>
  
  <p>I'm looking for an index that will match the following query:</p>
  
  <pre><code>let query: FilterQuery&lt;ITimer&gt; = {
      start: {$gte: start, $lte: end},
      userId: userId,
  };
  </code></pre>
  
  <p>Where <em>start</em> and <em>end</em> parameters are date objects or ISOStrings passed to define a range of days.</p>
  
  <p>Here I invoke the query, sorting results:</p>
  
  <pre><code>let result = await collection.find(query).sort({start: 1}).toArray();
  </code></pre>
  
  <p>It seems simple enough that the following index would match the above query:</p>
  
  <pre><code>{
      key: {
          start: 1,
          userId: 1,
      },
      name: 'find_between_dates_by_user',
      background: true,
      unique: false,
  },
  </code></pre>
  
  <p>But using mongodb-compass to monitor the collection, I see this index is not used.
  Moreover, mongodb documentation specifically states that if an index matches a query completely, than no documents will have to be examined, and the results will be based on the indexed information alone.
  unfortunately, for every query I run, I see documents ARE examined, meaning my indexes do not match.</p>
  
  <p>Any suggestions? I feel this should be very simple and straightforward, but maybe I'm missing something.
  attached is an screenshot from mongodb-compass 'explaining' the query and execution. </p>
  
  <p><a href="https://i.stack.imgur.com/RChtA.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/RChtA.png" alt="linked image"></a></p>