title: MongoDB - Query conundrum - Document refs or subdocument
body: <p>I've run into a bit of an issue with some data that I'm storing in my MongoDB (Note: I'm using mongoose as an ODM). I have two schemas:</p>
  
  <pre><code>mongoose.model('Buyer',{
    credit: Number,
  })
  </code></pre>
  
  <p>and </p>
  
  <pre><code>mongoose.model('Item',{
    bid: Number,
    location: { type: [Number], index: '2d' }
  })
  </code></pre>
  
  <p>Buyer/Item will have a parent/child association, with a one-to-many relationship. I know that I can set up Items to be embedded subdocs to the Buyer document <strong>or</strong> I can create two separate documents with object id references to each other. </p>
  
  <p>The problem I am facing is that I need to query Items <strong>where it's bid is lower than Buyer's credit</strong> but also <strong>where location is near a certain geo coordinate</strong>.</p>
  
  <p>To satisfy the first criteria, it seems I should embed Items as a subdoc so that I can compare the two numbers. But, in order to compare locations with a geoNear query, it seems it would be better to separate the documents, otherwise, I can't perform geoNear on each subdocument.</p>
  
  <p>Is there any way that I can perform both tasks on this data? If so, how should I structure my data? If not, is there a way that I can perform one query and then a second query on the result from the first query?</p>
  
  <p>Thanks for your help!</p>