# Querying Activities

## Activity Search & Queries

You can query & search activities. Here's an example of how to query activities:

<codetabs>

<codetabs-item value="swift" label="Swift">

```swift
let query = ActivitiesQuery(
    filter: .equal(.type, "post"),
    sort: [Sort(field: .createdAt, direction: .reverse)],
    limit: 10
)
let activityList = client.activityList(for: query)
let activities = try await activityList.get()
```

</codetabs-item>

<codetabs-item value="javascript" label="JavaScript">

```js
client.queryActivities({
  filter: {
    activity_type: "post",
  },
  sort: [{ field: "created_at", direction: -1 }],
  limit: 10,
});
```

</codetabs-item>

<codetabs-item value="nodejs" label="Node">

```js
client.feeds.queryActivities({
  filter: {
    activity_type: "post",
  },
  sort: [{ field: "created_at", direction: -1 }],
  limit: 10,
});
```

</codetabs-item>

<codetabs-item value="go-golang" label="Go">

```go
// Query activities with basic filters
queryResponse, err := feedsClient.QueryActivities(ctx, &getstream.QueryActivitiesRequest{
    Filter: map[string]interface{}{
        "type": "post",
    },
    Limit: getstream.PtrTo(10),
    Sort:  []map[string]interface{}{
        {"field": "created_at", "direction": -1}, // descending
    },
})
if err != nil {
    log.Fatal(err)
}
log.Printf("Found %d activities", len(queryResponse.Data.Activities))

for _, activity := range queryResponse.Data.Activities {
    log.Printf("Activity: %+v", activity)
}
```

</codetabs-item>

</codetabs>

The syntax emulates a MongoDB style query syntax. (It emulates it, we don't use MongoDB, but the query syntax is nice here).

### Querying activities by text

<codetabs>

<codetabs-item value="swift" label="Swift">

```swift
// search for activities where the text includes the word 'popularity'.
let query = ActivitiesQuery(
    filter: .query(.text, "popularity")
)
let activityList = client.activityList(for: query)
let activities = try await activityList.get()
```

</codetabs-item>

<codetabs-item value="javascript" label="JavaScript">

```js
client.queryActivities({
  filter: {
    text: {
      $q: "popularity",
    },
  },
});
```

</codetabs-item>

<codetabs-item value="nodejs" label="Node">

```js
client.feeds.queryActivities({
  filter: {
    text: {
      $q: "popularity",
    },
  },
});
```

</codetabs-item>

</codetabs>

### Querying activities by search data

Consider this example activity:

```json
{
  "id": "activity-123",
  "type": "post",
  "text": "Check out our spring sale!",
  "search_data": {
    "campaign": {
      "id": "spring-sale-2025",
      "location": {
        "mall": "yorkdale",
        "city": "toronto",
        "country": "canada"
      }
    }
  }
  // ... other activity fields
}
```

You can search this activity using the `search_data` field in several ways:

<codetabs>

<codetabs-item value="swift" label="Swift">

```swift
// search for activities associated with the campaign ID 'spring-sale-2025'
let searchValue: [String: RawJSON] = ["campaign": .dictionary(["id": .string("spring-sale-2025")])]
let query = ActivitiesQuery(
    filter: .contains(.searchData, searchValue)
)
let activityList = client.activityList(for: query)
let activities = try await activityList.get()

// search for activities where the campaign took place in a mall
let query2 = ActivitiesQuery(
    filter: .pathExists(.searchData, "campaign.location.mall")
)
let activityList2 = client.activityList(for: query2)
let activities2 = try await activityList2.get()
```

</codetabs-item>

<codetabs-item value="javascript" label="JavaScript">

```js
client.queryActivities({
  filter: {
    search_data: { $contains: { campaign: { id: "spring-sale-2025" } } },
  },
});

client.queryActivities({
  filter: {
    search_data: { $path_exists: "campaign.location.mall" },
  },
});
```

</codetabs-item>

<codetabs-item value="nodejs" label="Node">

```js
client.feeds.queryActivities({
  filter: {
    search_data: { $contains: { campaign: { id: "spring-sale-2025" } } },
  },
});

client.feeds.queryActivities({
  filter: {
    search_data: { $path_exists: "campaign.location.mall" },
  },
});
```

</codetabs-item>

</codetabs>

### Activities Queryable Built-In Fields

<partial id="activity-feeds/v3-latest/_default/_partials/activities-queryable-fields"></partial>

Be sure to reach out to support if you need additional query activity capabilities.

### Activities sort options

<partial id="activity-feeds/v3-latest/_default/_partials/activities-sort-fields"></partial>

---

This page was last updated at 2025-08-15T14:14:09.562Z.

For the most recent version of this documentation, visit [https://getstream.io/activity-feeds/docs/react-native/query-activities/](https://getstream.io/activity-feeds/docs/react-native/query-activities/).