title: bson.D vs bson.M for find queries
body: <p>This specifc question is in relation to using mongodb with the golang package <a href="https://godoc.org/go.mongodb.org/mongo-driver" rel="noreferrer"><code>mongo-driver</code></a>, but I would assume this applies across most interfaces with mongodb.</p>
  <p>When using <a href="https://godoc.org/go.mongodb.org/mongo-driver/mongo#Collection.Find" rel="noreferrer"><code>Find</code></a> to query some data from a collection, we can use both the <a href="https://godoc.org/go.mongodb.org/mongo-driver/bson#M" rel="noreferrer"><code>bson.M</code></a>- and <a href="https://godoc.org/go.mongodb.org/mongo-driver/bson#D" rel="noreferrer"><code>bson.D</code></a>-type to specify the filter for this find.</p>
  <p>As per the documentation <code>bson.D</code> should be used if the order of elements matters and <code>bson.M</code> should be used otherwise.</p>
  <blockquote>
  <p>D is an ordered representation of a BSON document. This type should be used when the order of the elements matters, such as MongoDB command documents. If the order of the elements does not matter, an M should be used instead.</p>
  </blockquote>
  <p>Now my question is whether the use of either of these, i.e. ordered vs unordered, structures has an effect on the query plan generated by the mongo query optimizer.</p>
  <p>In a classic SQL database the order usually doesn't matter as the optimizer is smart enough to use summary statistics, indexes, etc. to determine which queries to execute first.</p>
  <p>Can I assume this to be the case here as well, or does using an ordered structure to query my collection somehow interfere with this / does using an ordered structure work similar to using optimizer hints? If there is some interference, is this influenced at all by if the fields to search through are indexed?</p>