Sanity CMS Quiz: GROQ Queries and Realtime Collaboration Quiz

Challenge your understanding of GROQ queries and realtime collaboration within content management workflows. This quiz covers query syntax, filtering, ordering, projection, and the principles behind collaborative editing experiences.

  1. GROQ Syntax Fundamentals

    Which clause in a GROQ query is used to filter documents by a specific field value, such as selecting all posts where the type is 'article'?

    1. filter
    2. select
    3. where
    4. order

    Explanation: The 'filter' clause is used in GROQ queries to filter documents based on certain criteria, such as field values. 'where' and 'select' are not valid GROQ keywords, although they may sound familiar from other query languages. 'order' is used for sorting results, not filtering. Only 'filter' accurately matches the GROQ syntax for selecting specific data.

  2. Query Projection Understanding

    In a GROQ query, which symbol is used immediately after a filter to specify which fields should be returned, such as returning only 'title' and 'slug'?

    1. -u003E
    2. ]
    3. { }
    4. |

    Explanation: Curly braces '{ }' are used in GROQ queries to define a projection, specifying which fields to include in the results. The '-u003E' symbol is for dereferencing pointers to linked documents. The '|' symbol is not used in this context in GROQ, while ']' is a closing bracket for arrays, not projections. Only '{ }' serves the required purpose in this scenario.

  3. Ordering Results in GROQ

    How would you specify that results should be sorted in descending order by their publish date in a GROQ query?

    1. sort(publishDate descending)
    2. order(publishDate desc)
    3. order by publishDate DESC
    4. orderby:publishDate:-1

    Explanation: The 'order(field desc)' clause is the correct way to sort results in descending order for a specific field in GROQ. 'sort(publishDate descending)' and 'orderby:publishDate:-1' are not valid GROQ syntax. 'order by publishDate DESC' resembles SQL rather than GROQ. Only 'order(publishDate desc)' matches the language rules for proper ordering.

  4. Realtime Collaboration Concept

    Which feature is essential for supporting simultaneous content editing by multiple users in a realtime collaboration environment?

    1. Conflict-free data structures
    2. Version locking
    3. Scheduled publishing
    4. Static site generation

    Explanation: Conflict-free data structures, such as CRDTs, are crucial for enabling simultaneous editing by multiple users without overwriting changes. Version locking would prevent others from editing at the same time, conflicting with collaboration goals. Static site generation is unrelated to realtime editing, focusing instead on website building. Scheduled publishing automates when content goes live but does not solve collaborative editing challenges.

  5. Filtering Documents by Array Fields

    If you want to select all documents where the 'tags' array contains the value 'featured', which operator should you use in a GROQ filter?

    1. contains
    2. matches
    3. []
    4. in

    Explanation: The 'in' operator in GROQ is used to check if a value exists inside an array, making it ideal for scenarios like finding documents where 'tags' contains 'featured'. 'matches' is used for pattern matching strings, not arrays. 'contains' is not a valid GROQ operator, though it is common in other languages. '[]' is used for indexing in arrays but not for filtering by array contents.