title: Mongo / Express Query Nested _id from query string
body: <p>Using: node/express/mongodb/mongoose</p>
  
  <p>With the setup listed above, I have created my schema and model and can query as needed. What I'm wondering how to do though is, pass the express request.query object to Model.find() in mongoose to match and query the _id of a nested document. In this instance, the query may look something like:</p>
  
  <pre><code>http://domain.com/api/object._id=57902aeec07ffa2290f179fe
  </code></pre>
  
  <p>Where object is a nested object that exists elsewhere in the database. I can easily query other fields. _id is the only one giving an issue. It returns an empty array of matches.</p>
  
  <p>Can this be done?</p>
  
  <p>This is an example and not the ACTUAL schema but this gets the point across..</p>
  
  <pre><code>let Category = mongoose.Schema({
      name: String
  })
  
  let Product = mongoose.Schema({
      name: String,
      description:String,
      category:Category
  })
  
  // sample category..
  {
      _id:ObjectId("1234567890"),
      name: 'Sample Category'
  }
  
  // sample product
  {
      _id:ObjectId("0987654321"),
      name:'Sample Product',
      description:'Sample Product Description',
      category: {
          _id:ObjectId("1234567890"),
          name: 'Sample Category'
      }
  }
  </code></pre>
  
  <p>So, what I'm looking for is... if I have the following in express..</p>
  
  <pre><code>app.get('/products',function(req,res,next){
      let query = req.query
      ProductModel.find(query).exec(function(err,docs){
          res.json(docs)
      })
  })
  </code></pre>
  
  <p>This would allow me to specify anything I want in the query parameters as a query. So I could..</p>
  
  <pre><code>http://domain.com/api/products?name=String
  http://domain.com/api/products?description=String
  http://domain.com/api/products?category.name=String
  </code></pre>
  
  <p>I can query by category.name like this, but I can't do:</p>
  
  <pre><code>http://domain.com/api/products?category._id=1234567890
  </code></pre>
  
  <p>This returns an empty array</p>