
Grab your gear: The official Sanity swag store
Read Grab your gear: The official Sanity swag storeYou're on the right track! To filter by items that don't have a property set, you need to use the defined() function in GROQ.
The correct syntax is:
*[!defined(prop)]This will return all documents where the prop field is not defined or is null.
So if you wanted to filter posts that don't have a publishedAt property set, you'd write:
*[_type == 'post' && !defined(publishedAt)]The defined() function returns true if the property exists and is not null, and false otherwise. By negating it with !, you get documents where the property is missing or null.
Just using *[!prop] doesn't work because GROQ needs the explicit defined() function to check for property existence. And prop == null won't catch cases where the property doesn't exist at all on the document (as opposed to existing but being set to null).
You can read more about the defined() function in the GROQ documentation.
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