title: Marklogic QueryByExample in collection NodeJS
body: <p><strong>TLDR</strong></p>
  
  <p>Is there a way to limit queryByExample to a collection in NodeJS?</p>
  
  <p><strong>Problem faced</strong></p>
  
  <p>I have a complex query with some optional fields (i.e. sometimes some search fields will be omitted). So I need to create a query dynamically, e.g. in JSON. QueryByExample seems to be the right tool to use here as it gives me that flexibility to pass a JSON. However my problem is that I would like to limit my search to only one collection or directory.</p>
  
  <p>e.g. I was hoping for something like</p>
  
  <pre><code>searchJSON = {
          title: { $word: "test" },
          description: { $word: "desc" }
  };
  
  //query
  db.documents.query(qb.where(
      qb.collection("collectionName"),
      qb.byExample(searchJSON)
  )).result()...
  </code></pre>
  
  <p>In this case <code>searchJSON</code> could have been built dynamically, for example maybe sometimes title may be omitted from the search.</p>
  
  <p>This doesn't work because the query builder only allows queryByExample to be the only query. But I'd instead like to built a dynamic search query which is limited to a collection or directory.</p>