title: MongoDB query an array for an exact element match, but may be out of order
body: <p>I have a document in MongoDB that looks like this:</p>
  
  <pre><code>{ users: ["2", "3", "4"] }
  </code></pre>
  
  <p>I'm try to query this document by matching the users array.</p>
  
  <pre><code>db.things.find( { users: { $all: [ "2", "3", "4" ] } } )
  </code></pre>
  
  <p>That query works, but would also return this document:</p>
  
  <pre><code>{ users: ["2", "3", "4", "5"] }
  </code></pre>
  
  <p>Last requirement is to be able to query the users array with the elements out of order, say <code>[ "3", "4", "2" ]</code> in the query, and it be able to return my first document listed.</p>
  
  <p>Any help would be greatly appreciated.  Thanks in advance.</p>
  
  <p>I'm also using mongoid, if that has a helper that anyone knows about, but can do a straight mongo query if I need to.</p>