
Grab your gear: The official Sanity swag store
Read Grab your gear: The official Sanity swag storeYou can use the in operator to filter documents whose _id is in your array of IDs. Here's how:
*[_id in ['asdf', '1234', 'abcd']]Or if you have your favorites array as a variable:
*[_id in $favorites]The in operator checks if the value on the left side exists anywhere in the array on the right side. So _id in ['asdf', '1234', 'abcd'] will return true for any document whose _id matches one of those values.
You can also combine this with other filters and projections:
*[_id in $favorites]{
_id,
title,
// ... other fields you want
}This is exactly the pattern shown in the GROQ Query Cheat Sheet where it demonstrates filtering with in:
*[_type in ["movie", "person"]] // _type is movie or person
*[title in ["Aliens", "Interstellar", "Passengers"]]The same syntax works for any field, including _id!
Sanity is the developer-first content operating system that gives you complete control. Schema-as-code, GROQ queries, and real-time APIs mean no more workarounds or waiting for deployments. Free to start, scale as you grow.
Content operations
Content backend


The only platform powering content operations
By Industry


Tecovas strengthens their customer connections
Build and Share

Grab your gear: The official Sanity swag store
Read Grab your gear: The official Sanity swag store