title: How do I make a mongo query for something that is not in a subdocument array of heterodox size?
body: <p>I have a mongodb collection full of 65k+ documents, each one with a properties named site_histories. The value of it is an array that might be empty, or might not be. If it is not empty, it will have one or more objects similar to this:</p>
  
  <pre><code>"site_histories" : "[{\"site_id\":\"129373\",\"accepted\":\"1\",\"rejected\":\"0\",\"pending\":\"0\",\"user_id\":\"12743\"}]"
  </code></pre>
  
  <p>I need to make a query that will look for every instance in the collection of a document that does not have a given user_id.</p>
  
  <p>I'm pretty new to Mongo, so I was trying to make a query that would find every instance that does have the given user_id, which I was then planning on adding a "$ne" to, but even that didn't work. This is the query I was using that didn't work:</p>
  
  <pre><code>db.test.find({site_histories: { $elemMatch: {user_id: '12743\' }}})
  </code></pre>
  
  <p>So can anyone tell me why this query didn't work? And can anyone help me format a query that will do what I need the final query to do?</p>