title: MongoDB using an OR clause in mongoengine
body: <p>I'm using python's mongoengine to query MongoDB, and have loved it for the most part, but I'm having an issue with an <a href="https://docs.mongoengine.org/guide/querying.html#advanced-queries" rel="nofollow noreferrer">advanced query</a>.</p>
  <p>Here's my model</p>
  <pre><code>class ContentItem(Document):
      account = ReferenceField(Account)
      creator = ReferenceField(User)
      public = BooleanField(default=False) 
      last_used = DateTimeField(default=datetime.now)
  </code></pre>
  <p>I would like to make a query for all <code>ContentItem</code>'s that are of a particular account, and are either created by the logged in user or are public.  Here's the query I wrote</p>
  <pre><code>query = ContentItem.objects.filter( (Q(account=account) &amp; Q(public=True)) |  (Q(account=account) &amp; Q(creator=logged_in_user)) ).order_by('-last_used')
  </code></pre>
  <p>or:</p>
  <pre><code>query = ContentItem.objects.filter( Q(account=account) &amp; ( Q(public=True) |  Q(creator=logged_in_user) ) ).order_by('-last_used')
  </code></pre>
  <p>But these seem to be XOR where if either <code>public</code>, or the <code>creator</code> but not both. Is this expected?</p>
  <p>Am I overlooking something? Should I do this directly with mongodb instead of mongoengine?</p>
  <p>My current workaround is to make two different queries and combine the results,  but as the # of Content Items gets larger the result is taking a long time to come back because I need to get all items before I can order them, thereby losing all the benefit of (django) paginated results.</p>