0

I have a document which has many properties. There is also a boolean in all the sub documents called featured. Now I want to make a query that would return 2 documents with featured being true and 6 documents with featured being false. Currently my query is :

*[_type == "reviews" ]{
    title,
    _id,
    featured,
    publishedAt,
    coverImage,
    description,
    author,userInfo,
    publishedAt,
    slug,body,
    "timeRead": round(length(pt::text(body)) / 5 / 180 ),
    mainImage{
      asset->{
      _id,
      url
    }
  }
  }

It returns all the documents.

I have tried using different queries but non gave me the desired result. I can surely make two different queries and use a variable to store them such as:

[ {"isFeatured":*[_type == "reviews" && featured==false ][0..5]{
    title,
    _id,
    featured,
    publishedAt,
    coverImage,
    description,
    author,userInfo,
    publishedAt,
    slug,body,
    "timeRead": round(length(pt::text(body)) / 5 / 180 ),
    mainImage{
      asset->{
      _id,
      url
    }
  }
  }},{
"isNotFeatured":*[_type == "reviews"  && featured==true ][0..2]{
    title,
    _id,
    featured,
    publishedAt,
    coverImage,
    description,
    author,userInfo,
    publishedAt,
    slug,body,
    "timeRead": round(length(pt::text(body)) / 5 / 180 ),
    mainImage{
      asset->{
      _id,
      url
    }
  
}}}]

It returns an array with two objects with one having isFeatured object containing the featured posts and second having isNotFeatured object with not featured posts but I don't want that. I want one one array object to contain all of them.

Rao Asim
  • 158
  • 8

0 Answers0