GROQ query for Mux video asset returning only _ref instead of full data
The issue you're encountering is a common one when working with Mux videos in Sanity! You're getting just a _ref because you need to use the dereference operator (->) in your GROQ query to expand the reference and get the full asset data.
The blog post example you're following uses Mux video inside a Portable Text field (that's what the text[] part is about), but it sounds like you have a direct video field on your document instead.
For a direct video field on your document type, your GROQ query should look like this:
*[_type == "video"]{
...,
'video': video.asset->
}This will dereference the asset and give you all the Mux asset data including playbackId, status, data, and other metadata that the sanity-mux-player component needs.
If you want to be more explicit about what data you're fetching, you can also write it like:
*[_type == "video"]{
...,
video {
asset-> {
playbackId,
status,
data
}
}
}The key is that -> operator after asset - that tells GROQ to follow the reference and return the actual asset document instead of just the reference object with _ref.
Once you have the playbackId in your query results, you can pass the asset data directly to the sanity-mux-player component's assetDocument prop, and it should handle the rest! The player component expects the full asset document with all the Mux metadata, which is why dereferencing is essential here.
Show original thread9 replies
Sanity – Build the way you think, not the way your CMS thinks
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.