See Sanity in action 👀 Join us for a live product demo + Q&A →

Getting an Array of References without an Object Wrapper

1 replies
Last updated: Jan 6, 2023
Can I get an array of references without an object wrapper? When i write:
*[_id == $id ].featuredPosts[]->{The elements I want}
it returns null, and if I instead wrap featuredPosts with curly brackets it returns what I want, but with the additional layer
{featuredPosts: [Result I want to be returned]}
Jan 6, 2023, 2:52 PM
Figured it out. I could just add parentheses like this:
*[_id == $id ].(featuredPosts[]->{The elements I want})[0]
Jan 6, 2023, 3:05 PM – build remarkable experiences at scale

Sanity is a customizable solution that treats content as data to power your digital business. Free to get started, and pay-as-you-go on all plans.

Categorized in