Unable to create a flexible sync subscription on an indexed queryable field

Hi! I am trying to create a flexible sync subscription in Realm Swift to subscribe to all Items where the owner_id is either the user.id or a GLOBAL_ID.

subs.append(QuerySubscription<Item>(name: String(describing: Item.self))  {
                        $0.owner_id.in([user.id, GLOBAL_ID])
                 })

I always get the error: Received QUERY_ERROR “Client provided query with bad syntax: the indexed queryable field must be ANDed with the remainder of the query”

It seems like under the hood the query string is always converted to (owner_id == ‘user_id_string’ or owner_id == GLOBAL_ID), even if I use the IN keyword. I understand that using OR in a query on an indexed queryable field is not supported, but I thought that using IN was an acceptable substitute?

I’ve also tried creating a NSPredicate string, and appending two separate subscriptions to the set, but nothing’s worked.

This same query (using IN, not OR) works fine on my Node.js client. Is there any way to get this to work in Swift or is it a limitation of the SDK?

Hi Lina! As you’ve pointed out, it looks like the Swift SDK is converting your IN expression to an OR under the hood at the moment which is causing query validation to fail. As the swift SDK does not support the Realm Query Language there’s currently no way to explicitly tell the sdk what query you’d like it to send to the server at the moment, and thus queries on multiple indexed queryable fields are not supported.

Fortunately we’ve just finished up a change to relax the server validation for the case you describe above with queries that are syntactically equivalent to an IN like (owner_id == ‘user_id_string’ OR owner_id == GLOBAL_ID) that you can expect to land sometime in the middle of next week!

Hi @squishy, these changes are now live! Please let us know if you’re still having issues with the validation of your query