javascriptsanitygroq

How to define NOT is sanity.io structure builder?


I'm trying to filter all products without categories (which is array of references) and can't find how to do it.

S.listItem()
  .title('Without category')
  .id('productsWithoutCategories')
    .child(
      S.documentList()
        .title('Without categories')
        .menuItems(S.documentTypeList('product').getMenuItems())
        .filter('_type == $type && !category')
        .params({ type: 'product' })
      )

!category not working. I will be grateful for the help.


Solution

  • Finded answer with Vision (really pleasant tool)

    https://www.sanity.io/docs/the-vision-plugin

     .filter('_type == $type && !defined(categories)')
     .params({ type: 'product' })