Facet Count Incorrect

Hi,

I’m using “realm-web”: “^1.1.0” on ReactJS. I’m trying to convert my queries to use $facet to reduce my queries. The results that I’m getting from $facet queries are nonexistent or a lot lower than running the queries by themselves. I ran a basic aggregate in the Atlas GUI and with the Realm SDK. I get 291 from the GUI vs 115 in SDK. What’s causing the inconsistency? I generated the aggregate in the GUI and copy/pasted into my SDK.

[
    {
      '$match': {
        'email': 'test@email.com'
      }
    }, {
      '$facet': {
        'attempt': [
          {
            '$count': 'count'
          }
        ]
      }
    }
   ]

There are some differences but I can say if they can explain what you observe from the information given.

Hi Winston – One way to explain the difference may be Rules. For Web requests Realm will use Rules to figure out which documents can/cannot be seen by a user and this can impact aggregation results unless the code is within a Function run as a System Function (which explicitly skips rules).

1 Like

Thanks for pointing me in the right direction.

This topic was automatically closed 5 days after the last reply. New replies are no longer allowed.