Search And Data Processing

Contains operator for filtering arrays by arrays

Summary

Hello there! In this guide, we'll walk through how to use the powerful filtering capabilities in Xano to fetch conversations based on the members (users) involved. This can be incredibly useful for building features like group chats, collaboration tools, or any application that involves multiple users interacting within a shared context.

Let's get started!

Step 1: Access the Conversations Table

First things first, navigate to the Conversations table in your Xano project. This is where we'll be performing our filtering operation.

Step 2: Identify the Members Column

The Conversations table likely has a column that stores an array of references to the members (users) involved in each conversation. In our example, this column is called `members`.

Step 3: Use the `contains` Operator

Xano provides a handy operator called `contains` that allows us to filter arrays based on exact matches. This is perfect for our use case!

To use the `contains` operator, follow these steps:

  1. In the filter section of your Conversations table, click on the `members` column.
  2. Select the `contains` operator from the list of available options.
  3. In the input field that appears, enter the user IDs (or any unique identifiers) of the members you want to filter by.

For example, if you want to fetch all conversations that involve users with IDs 1, 3, and 5, you can enter `1, 3, 5` in the input field.

Step 4: Observe the Results

After entering your desired member IDs, you'll see the table update in real-time, displaying only the conversations that match your filter criteria.

Here's an example of what the filtered results might look like:

ID | members 2 | [1, 3, 5, 7] 3 | [1, 3, 5]

In this case, we filtered for conversations involving users 1, 3, and 5, and the table returned two conversations (IDs 2 and 3) that match that criteria.

The `contains` Operator vs. the `in` Operator

It's worth noting that the `contains` operator differs from the `in` operator in its behavior. The `in` operator will match any array that contains at least one of the values in your input, while `contains` is more strict and will only match arrays that contain all the specified values.

For example, if you use `in` with the input `1, 3, 5`, it might return conversations with member arrays like `[1, 2, 3]`, `[4, 5]`, or `[1, 3, 5, 6]`. On the other hand, `contains` with the same input will only return conversations with the exact member array `[1, 3, 5]`.

Wrapping Up

By leveraging the powerful filtering capabilities of Xano, you can easily fetch conversations based on the members involved. The `contains` operator is a straightforward and efficient way to achieve this, allowing you to build collaborative features and enhance the user experience of your application.

Remember, Xano empowers you to build powerful backend services without writing a single line of code, making it an invaluable tool for developers and non-technical users alike.

Happy building!

This transcript was AI generated to allow users to quickly answer technical questions about Xano.

Was this helpful?

I found it helpful

I need more support
Sign up for XanoSign up for Xano

Build without limits on a secure, scalable backend.

Unblock your team's progress and create a backend that will scale for free.

Start building for free