Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Fetching documents

Using Sanity Studio I’ve created 2 documents in a simple schema "users" (the structure is not that important), and then updated each of them with some values, and published.

Trying to get the results using the query:

*[_type=="users"]

instead of getting 2 documents, I’ve got 4, and it seems each update created a new revision and all revisions of all documents were returned.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

Is this how Sanity’s edit works each time? If so, how do I just get the 2 documents with all the latest changes?

>Solution :

It sounds like you’re probably getting both the published and the draft versions of each document. A draft will have the same _id as the published document but will be prepended with drafts..

This might be a bit clearer if you modify your query to the following, which will return an array of _ids:

*[_type=="users"]._id

If this is in fact what’s happening, you can modify your query to exclude drafts:

*[_type=="users" && !(_id in path("drafts.**"))]

Here’s a bit more detail about drafts.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading