# recentlyViewedSpaces() in CQL: syntax and examples

URL: https://goingstellar.ro/reference/cql/recentlyviewedspaces/

recentlyViewedSpaces() returns the keys of the spaces the logged-in user viewed recently. You use it on the space field to search the places you have actually been working in, without starring them. It takes one number, the limit.

## Syntax

```
s
p
a
c
e
 
I
N
 
r
e
c
e
n
t
l
y
V
i
e
w
e
d
S
p
a
c
e
s
(
l
i
m
i
t
)
```

## Arguments

- `limit` (optional: yes): How many recently viewed spaces to take. Required.

## Works with

- Fields: space.
- Operators: IN and NOT IN. = fails because the function returns a list.
- Functions: can sit in the same list as plain space keys.
- Not with: no argument, or a second argument.

## Examples

```
space in recentlyViewedSpaces(10)
```

Content from the ten spaces you opened most recently. Run on Confluence Cloud on 2026-11-29.

```
space IN recentlyViewedSpaces(3) AND title ~ "runbook"
```

Look for a runbook only in the few spaces you were in lately. Run on Confluence Cloud on 2026-11-29.

```
space IN recentlyViewedSpaces(10) AND type = page AND lastmodified >= now("-1w")
```

Pages changed this week in the spaces you visit, a lightweight daily check. Run on Confluence Cloud on 2026-11-29.

```
space IN (recentlyViewedSpaces(10), 'SD')
```

Recent spaces plus one fixed space that must always be included. Run on Confluence Cloud on 2026-11-29.

```
space NOT IN recentlyViewedSpaces(10) AND type = page
```

Pages in spaces you have not visited recently. Run on Confluence Cloud on 2026-11-29.

## Pitfalls

- The documentation says the limit must not exceed 200, but `recentlyViewedSpaces(200)` fails with "Recents CQL query page size exceeds limit". 199 runs (checked on Confluence Cloud, November 2026).
- There is no default. `recentlyViewedSpaces()` fails with "Could not parse cql", and so does a second argument as in `recentlyViewedSpaces(10, 5)`. Unlike recentlyViewedContent(), there is no offset.
- `space = recentlyViewedSpaces(10)` fails with "Unable to execute function 'recentlyViewedSpaces', expecting a function that returns a single value". Use IN.
- A limit of 0 runs and matches nothing. The list depends on the person who runs the query, so shared saved searches behave differently for each user.

## Related

- [favouriteSpaces()](https://goingstellar.ro/reference/cql/favouritespaces/)
- [recentlyViewedContent()](https://goingstellar.ro/reference/cql/recentlyviewedcontent/)
- [currentUser()](https://goingstellar.ro/reference/cql/currentuser/)
- [now()](https://goingstellar.ro/reference/cql/now/)
- [space](https://goingstellar.ro/reference/cql/space-field/)

## Sources

- [CQL functions (Atlassian Developer, Confluence Cloud)](https://developer.atlassian.com/cloud/confluence/cql-functions/)

