title: CouchBase Lite, exclude documents with certain keys in query
body: <p>I have a simple view with mapper that emits docs with some keys.</p>
  
  <pre><code>    com.couchbase.lite.View view = database.getView(VIEW_NAME);
      if (view.getMap() == null) {
          Mapper map = new Mapper() {
              @Override
              public void map(Map&lt;String, Object&gt; document, Emitter emitter) {
                  if ("user".equals(document.get("type"))) {
                      emitter.emit(document.get("name"), document); 
                  }
              }
          };
          view.setMap(map, null);
      }
  </code></pre>
  
  <p>having this View, i can than create Queries on it, with certain parameters like setKeys, startKey, endKey, setDescending, setDescending, setSkip and others as described in couchbase <a href="http://docs.couchbase.com/couchbase-manual-2.0/" rel="nofollow">manual</a>.</p>
  
  <p>If i write </p>
  
  <pre><code>    Query query = view.createQuery();
      List&lt;Object&gt; keys = new ArrayList&lt;&gt;();
      keys.add("User Name");
      query.setKeys(keys);
  </code></pre>
  
  <p>that query would return all docs matching "User Name" key.</p>
  
  <p>But I couldn't find a simple way to write queries that excludes (omits) docs with certain keys (like opposite to setKeys() function)</p>
  
  <p>one hack was found in <a href="https://github.com/couchbaselabs/ToDoLite-Android/blob/master/ToDoLite/src/main/java/com/couchbase/todolite/document/Profile.java" rel="nofollow">ToDoLite Example</a>
  The code looks like this:</p>
  
  <pre><code>public static Query getQuery(Database database, final String ignoreUserId) {
      com.couchbase.lite.View view = database.getView(VIEW_NAME);
      if (view.getMap() == null) {
          Mapper map = new Mapper() {
              @Override
              public void map(Map&lt;String, Object&gt; document, Emitter emitter) {
                  if ("user".equals(document.get("type"))) {
                      if (ignoreUserId == null ||
                              (ignoreUserId != null &amp;&amp;
                                      !ignoreUserId.equals(document.get("user_id")))) {
                          emitter.emit(document.get("name"), document);
                      }
                  }
              }
          };
          view.setMap(map, null);
      }
  
      Query query = view.createQuery();
      return query;
  }
  </code></pre>
  
  <p>Note that the view will only exclude key <em>ignoreUserId</em> you passed to it during the first call, and will ignore all the others during next calls (because it will create view only once during the first call)</p>
  
  <p>So you need to create new view for every key they want to omit.
  But if you have a lot of keys you want to exclude or does it often, it would be inefficient and boilerplate. </p>
  
  <p>Do you know any better solution or hack ?</p>
  
  <p>Any help appreciated<br>
  Thanks in advance</p>