{"id":4410,"date":"2018-01-03T10:28:26","date_gmt":"2018-01-03T18:28:26","guid":{"rendered":"https:\/\/www.couchbase.com\/blog\/?p=4410"},"modified":"2025-06-13T20:09:25","modified_gmt":"2025-06-14T03:09:25","slug":"querying-array-collections-couchbase-mobile","status":"publish","type":"post","link":"https:\/\/www.couchbase.com\/blog\/querying-array-collections-couchbase-mobile\/","title":{"rendered":"How to Query Array Collections in Couchbase Lite"},"content":{"rendered":"<p>One of the major features introduced in <a href=\"https:\/\/developer.couchbase.com\/documentation\/mobile\/2.0\/whatsnew.html\">Couchbase Lite 2.0<\/a>, is the new Query interface based on <a href=\"https:\/\/www.couchbase.com\/products\/n1ql\/\">N1QL<\/a>, Couchbase\u2019s declarative query language that extends SQL for JSON. If you are familiar with SQL, you will feel right at home with the semantics of the new API. We covered the basics of the interface in an earlier <a href=\"https:\/\/www.couchbase.com\/blog\/sql-for-json-query-interface-couchbase-mobile\/\">blog post<\/a>. Arrays are an integral component of modeling data with JSON. In this blog post, we will discuss querying of array collections using the new API.<\/p>\n<p>This blog assumes you are familiar with the fundamentals, so if you haven\u2019t done so already, be sure to review the <a href=\"https:\/\/www.couchbase.com\/blog\/sql-for-json-query-interface-couchbase-mobile\/\">earlier post<\/a> first. The last section of the post lists links to other relevant query blogs.<\/p>\n<div>You can download the Couchbase Mobile 2.0 Pre-release builds from our <a href=\"https:\/\/developer.couchbase.com\/documentation\/mobile\/2.0\/whatsnew.html\">downloads<\/a>\u00a0page.<\/div>\n<div><\/div>\n<p><!--more--><\/p>\n<h3 id=\"background\">Background<\/h3>\n<p>If you were using 1.x versions of Couchbase Mobile, you are probably familiar with <a href=\"https:\/\/developer.couchbase.com\/documentation\/mobile\/1.4\/training\/develop\/using-the-database\/index.html#query-documents\">Map-Views<\/a> for creating indexes and queries. In 2.0, you no longer have to create views and map functions! Instead, a simple interface allows you to create indexes and you can use a Query Builder interface to construct your queries. The new query interface is simpler to use and much more powerful in comparison. We will discover some of it\u2019s features in this post.<\/p>\n<h3 id=\"sampleproject\">Sample Project<\/h3>\n<p>While the examples discussed here use Swift for iOS, note that barring some minor differences, the same query interface is supported on the Android and Windows platforms as well. So with some minor tweaks, you should be able to reuse the query examples in this post when working with other platforms.<\/p>\n<p>Follow instructions below if you are interested in a sample Swift Project<\/p>\n<ul>\n<li>Clone the iOS Swift Playground from GitHub<\/li>\n<\/ul>\n<pre><code>$ git clone https:\/\/github.com\/couchbaselabs\/couchbase-lite-ios-api-playground<\/code><\/pre>\n<ul>\n<li>Follow the installation instructions in the corresponding <a href=\"https:\/\/github.com\/couchbaselabs\/couchbase-lite-ios-api-playground\/blob\/master\/README.md\">README<\/a> file to build and execute the playground.<\/li>\n<\/ul>\n<h3 id=\"sampledatamodel\">Sample Data Model<\/h3>\n<p>We shall use the Travel Sample database located <a href=\"https:\/\/github.com\/couchbaselabs\/couchbase-lite-ios-api-playground\/tree\/master\/travel-sample.cblite2\">here<\/a><\/p>\n<p>The sample data set includes several types of documents as identified by the <code>type<\/code> property in the document. We will focus on documents of <code>type<\/code> <em>\u201chotel\u201d<\/em> . The JSON document model is shown below. For brevity, we have omitted some of the properties from the model below.<\/p>\n<p>Specifically, note that the model includes nested collections &#8211; <code>public_likes<\/code> and <code>reviews<\/code>. The queries in following sections will be dealing with these nested collections.<\/p>\n<pre><code> {\r\n \"type\": \"hotel\",\r\n \"name\": \"Medway Youth Hostel\",\r\n \"address\": \"Capstone Road, ME7 3JE\",\r\n \"city\": \"Medway\",\r\n \"country\": \"United Kingdom\",\r\n \"description\": \"blah blah\",\r\n \"public_likes\": [\r\n \"Julius Tromp I\",\r\n \"Corrine Hilll\"\r\n ],\r\n \"reviews\": [\r\n {\r\n \"author\": \"Ozella Sipes\",\r\n \"content\": \"blah blah.\",\r\n \"date\": \"2013\u201306\u201322 18:33:50 +0300\",\r\n \"ratings\": {\r\n \"Cleanliness\": 5,\r\n \"Location\": 4,\r\n \"Overall\": 4,\r\n \"Rooms\": 3,\r\n \"Service\": 5,\r\n \"Value\": 4\r\n }\r\n },\r\n {\r\n \"author\": \"Jeremy Snapes\",\r\n \"content\": \"blah blah.\",\r\n \"date\": \"2013\u201305\u201305 18:33:50 +0300\",\r\n \"ratings\": {\r\n \"Cleanliness\": 2,\r\n \"Location\": 2,\r\n \"Overall\": 4,\r\n \"Rooms\": 3,\r\n \"Service\": 5,\r\n \"Value\": 4\r\n }\r\n }\r\n ],\r\n  \"url\":\"https:\/\/www.yha.org.uk\",\r\n    \"vacancy\": true\r\n    }<\/code><\/pre>\n<p>** Refer to the model above for each of the query examples below. **<\/p>\n<h3 id=\"thedatabasehandle\">The Database Handle<\/h3>\n<p>In the queries below, we will use the <a href=\"https:\/\/developer.couchbase.com\/documentation\/mobile\/2.0\/guides\/couchbase-lite\/native-api\/database\/index.html\"><code>Database<\/code><\/a> API to open\/create CouchbaseLite Database.<\/p>\n<pre><code> var options = DatabaseConfiguration()\r\n let db = try Database(name: kDBName, config: options)<\/code><\/pre>\n<h3 id=\"indexes\">Indexes<\/h3>\n<p>To speed up read queries, you can create Indexes on properties that you will query on. The performance improvement would be significant on large datasets. Of course, be aware that there will be an increase in storage needs in order to store the indexes and performance of writes can also be impacted. So be cautious of creating too many indexes.<\/p>\n<p>The following example creates a <code>ValueIndex<\/code> on the <code>type<\/code> property of a Document<\/p>\n<pre class=\"wrap:true lang:swift decode:true \"> try db.createIndex(IndexBuilder.valueIndex(items: ValueIndexItem.property(\"type\")),withName: \"typeIndex\")<\/pre>\n<p>The following example creates a <code>ValueIndex<\/code> on <code>type<\/code> and <code>name<\/code> properties of a Document<\/p>\n<pre class=\"wrap:true lang:swift decode:true \">try db.createIndex(IndexBuilder.valueIndex(items: ValueIndexItem.property(\"type\"),ValueIndexItem.property(\"name\")),withName: \"TypeNameIndex\")<\/pre>\n<h3 id=\"arraycontainment\">Array Containment<\/h3>\n<p>The query below fetches the <em>ids<\/em>, <em>names<\/em> and <em>public_likes<\/em> properties of documents where the <code>public_likes<\/code> array property in <em>\u201chotel\u201d<\/em> <code>type<\/code> documents contains the value of <em>\u201cCorrine Hilll\u201d<\/em>. For this, the <code>**ArrayFunction.contains**<\/code> function expression is used on the <code>public_likes<\/code> array.<\/p>\n<pre class=\"wrap:true lang:swift decode:true\">let searchQuery = QueryBuilde.select(SelectResult.expression(Meta.id),\r\n                  SelectResult.expression(Expression.property(\"name\")),\r\n                  SelectResult.expression(Expression.property(\"public_likes\")))\r\n .from(DataSource.database(db))\r\n .where(Expression.property(\"type\").equalTo(Expression.string(\"hotel\"))\r\n .and( ArrayFunction.contains(Expression.property(\"public_likes\"), value: Expression.string(\"Corrine Hilll\"))))<\/pre>\n<h3 id=\"arraysize\">Array Size<\/h3>\n<p>The query below fetches the <em>ids<\/em>, <em>names<\/em> properties and the <strong>size<\/strong> of <em>public_likes<\/em> array property in <em>\u201chotel\u201d<\/em> <code>type<\/code> documents. For this, the <code>**ArrayFunction.length**<\/code> function expression is used on the <code>public_likes<\/code> array to get the size of the array.<\/p>\n<p>Also, notice that we are using <code>as<\/code> expression to <em>alias<\/em> the array count value to <em>NumLikes<\/em>. We had introduced <em>aliases<\/em> in the earlier blog post on Query Fundamentals. If you do not alias the result of the <code>arrayLength<\/code> expression, the property key would be <code>$1<\/code> , which is not very intuitive.<\/p>\n<pre class=\"wrap:true lang:swift decode:true\"> let searchQuery = QueryBuilder.select(SelectResult.expression(Meta.id),\r\n           SelectResult.expression(Expression.property(\"name\")),\r\n           SelectResult.expression(ArrayFunction.length(Expression.property(\"public_likes\"))).as(\"NumLikes\"))\r\n .from(DataSource.database(db))\r\n .where(Expression.property(\"type\").equalTo(Expression.string(\"hotel\")))\r\n .limit(Expression.int(limit))<\/pre>\n<h3 id=\"evaluatingarraymembers\">Evaluating Array Members<\/h3>\n<p>While the <code>ArrayFunction.contains<\/code> function expression allows you to check if the given array contains a specific value, the <code>in<\/code> array expression can be used to evaluate any or all of the memebers of an array against a criteria specified by the <code>satisfies<\/code> expression. This is a powerful document filtering capability.<\/p>\n<p>The<code>in<\/code>expression is used with the <code>any<\/code>, <code>every<\/code> or the <code>anyAndEvery<\/code> quantified operators on <code>ArrayExpression<\/code> to evaluate any, every or any\/every element in the array object.<\/p>\n<p>The following query returns the documents where <code>any<\/code> of the values in the <code>public_likes<\/code> array begins with the characters \u201cCorr\u201d.<\/p>\n<pre class=\"wrap:true lang:swift decode:true\">\/\/1.\r\n let VAR_LIKEDBY = ArrayExpression.variable(\"likedby\")\r\n \r\n\/\/2.\r\n let searchQuery = QueryBuilder.select(SelectResult.expression(Meta.id),\r\n                  SelectResult.expression((Expression.property(\"public_likes\"))))\r\n.from(DataSource.database(db))\r\n.where(Expression.property(\"type\").equalTo(Expression.string(\"hotel\"))\r\n.and(ArrayExpression.any(VAR_LIKEDBY).in(Expression.property(\"public_likes\"))\r\n.satisfies(VAR_LIKEDBY.like(Expression.string(\"Cor%\")))))\r\n.limit(Expression.int(limit))<code><\/code><\/pre>\n<ol>\n<li style=\"list-style-type: none\">\n<ol>\n<li>Declare a variable with name \u201clikedby\u201d to represent every element in the <code>public_likes<\/code> array<\/li>\n<li>The <code>any<\/code> ArrayExpression checks if the array element represented by the <code>likedby<\/code> variable satisfies the criteria in the <code>like<\/code> expression. The <code>like<\/code> expression checks if the value of the item represented by the \u201clikedby\u201d variable begins with \u201cCor\u201d.<\/li>\n<\/ol>\n<\/li>\n<\/ol>\n<h3 id=\"indexingarrays\">Indexing Arrays<\/h3>\n<p>You can also query elements at specific indexes. The following query returns the <code>name<\/code> and first member of the <code>public_likes<\/code> array properties of all \u201chotel\u201d documents<\/p>\n<pre class=\"wrap:true lang:swift decode:true \"> let searchQuery = QueryBuilder.select(SelectResult.expression(Meta.id),\r\n           SelectResult.expression(Expression.property(\"name\")),\r\n           SelectResult.expression(Expression.property(\"public_likes[0]\")))\r\n .from(DataSource.database(db))\r\n .where(Expression.property(\"type\").equalTo(Expression.string(\"hotel\")))\r\n .limit(Expression.int(limit))<\/pre>\n<h3 id=\"evaluatingnestedarrays\">Evaluating Nested Arrays<\/h3>\n<p>You can evaluate the members a nested array. For this, you can apply a <code>keypath<\/code> to the variable expression. The nested array has to be one level deep.<\/p>\n<p>The following query returns the documents where <code>any<\/code> of the values in the nested <code>ratings<\/code> array has the <code>Overall<\/code> property rating that is greater than or equal to 4.<br \/>\nAs you may have noted from the data model above, the \u201creviews\u201d property holds an array of objects. Each of the objects contain a nested <code>ratings<\/code> array which in turn contains the <code>Overall<\/code> property.<\/p>\n<pre class=\"wrap:true lang:swift decode:true \">\/\/ 1.\r\n let VAR_OVERALL = ArrayExpression.variable(\"review.ratings.Overall\")\r\n \/\/2.\r\n let VAR_REVIEWS = ArrayExpression.variable(\"review\")\r\n \/\/3.\r\n let searchQuery = QueryBuilder.select(SelectResult.expression(Meta.id),\r\n          SelectResult.expression(Expression.property(\"name\")))\r\n .from(DataSource.database(db))\r\n .where(Expression.property(\"type\").equalTo(Expression.string(\"hotel\"))\r\n .and(ArrayExpression.any(VAR_REVIEWS).in(Expression.property(\"reviews\"))\r\n .satisfies(VAR_OVERALL.greaterThanOrEqualTo(Expression.int(4)))))\r\n .limit(Expression.int(limit))<\/pre>\n<ol>\n<li>Declare a variable to represent an element in the <code>review.ratings.Overall<\/code> array<\/li>\n<li>Declare a variable to represent every element in the <code>reviews<\/code> array<\/li>\n<li>The <code>any<\/code> expression checks if the array element represented by the <code>review<\/code> variable satisfies the criteria in the <code>comparison<\/code> expression. The <code>comparison<\/code> expression checks the value of <code>Overall<\/code> property of the <code>ratings<\/code> array in the object represented by the \u201creview\u201d variable is greater than or equal to 4.<\/li>\n<\/ol>\n<h3 id=\"limitations\">Limitations<\/h3>\n<p>The array manipulation capabilities are not nearly as extensive as N1QL\u2019s <a href=\"https:\/\/developer.couchbase.com\/documentation\/server\/5.0\/n1ql\/n1ql-language-reference\/arrayfun.html\">feature set<\/a>. But it\u2019s a good starting point. These capabilities may be available in future releases of Couchbase Mobile.<\/p>\n<p>So for now, it\u2019s upto the app to manipulate the array results using the language\u2019s collection processing capabilities.<\/p>\n<p>Let\u2019s consider this example in swift<\/p>\n<ul>\n<li>Referring to the data model, let\u2019s say you wanted to determine the <em>minimum<\/em> <code>Cleanliness<\/code> rating for a given hotel based on the reviews on the hotel.<\/li>\n<\/ul>\n<p>From the model above , note that the <code>Cleanliness<\/code> property is a member of the the <code>ratings<\/code> property contained in each object that is member of <code>reviews<\/code> array.<\/p>\n<figure><img decoding=\"async\" src=\"https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/2017\/12\/array_model_1.png\" alt=\"\" \/><\/figure>\n<p>For this, you can do a Couchbase Lite query to fetch the <code>reviews<\/code> array property for a hotel with specified Id as follows &#8211;<\/p>\n<pre class=\"wrap:true lang:swift decode:true \"> \/\/ 1. Query for reviews property array for the given hotel\r\n let searchQuery = QueryBuilder.select( \r\n        SelectResult.expression(Expression.property(\"reviews\")))\r\n .from(DataSource.database(db))\r\n .where(Expression.property(\"type\").equalTo(Expression.string(\"hotel\"))\r\n .and(Meta.id.equalTo(Expression.string(\"hotel_10025\"))))<\/pre>\n<p>The <code>resultSet<\/code> response to the above query would be an array with a single element. This element would correspond to the \u201chotel\u201d document for the specified Id.<\/p>\n<pre><code>[\r\n {\r\n \"reviews\": [\r\n {\r\n \"author\": \"Ozella Sipes\",\r\n \"content\": \"blah\",\r\n \"date\": \"2013\u201306\u201322 18:33:50 +0300\",\r\n \"ratings\": {\r\n \"Cleanliness\": 5,\r\n \"Location\": 4,\r\n \"Overall\": 4,\r\n \"Rooms\": 3,\r\n \"Service\": 5,\r\n \"Value\": 4\r\n }\r\n },\r\n {\r\n \"author\": \"fuzzy Snipes\",\r\n \"content\": \"blah\",\r\n \"date\": \"2013\u201306\u201322 18:33:50 +0300\",\r\n \"ratings\": {\r\n \"Cleanliness\": 2,\r\n \"Location\": 3,\r\n \"Overall\": 4,\r\n \"Rooms\": 3,\r\n \"Service\": 5,\r\n \"Value\": 4\r\n }\r\n }\r\n ]\r\n }\r\n]<\/code><\/pre>\n<p>Now, the app has to implement the logic to iterate over the <code>reviews<\/code> array and for each member of the array, to fetch the <code>ratings<\/code> property and corresponding <code>Cleanliness<\/code> value.<\/p>\n<p>Here is one possible way to do it in swift.<\/p>\n<ul>\n<li>First, iterate over the resultSet and extract the value of \u201creviews\u201d property.<\/li>\n<\/ul>\n<pre class=\"wrap:true lang:swift decode:true \"> var matches:[[String:Any]] = [[String:Any]]()\r\n do {\r\n       for row in try searchQuery.execute() {\r\n          if let reviewData = row.array(forKey: \"reviews\")?.toArray() as? [[String:Any]] {\r\n          matches.append(reviewData)\r\n      }\r\n    }\r\n }<\/pre>\n<p>After the loop processing, the \u201cmatches\u201d array would be something like the one below. It would be an array containing the nested array corresponding to the reviews &#8211;<\/p>\n<pre><code>[\r\n [\r\n {\r\n \"author\": \"Ozella Sipes\",\r\n \"content\": \"blah\",\r\n \"date\": \"2013\u201306\u201322 18:33:50 +0300\",\r\n \"ratings\": {\r\n \"Cleanliness\": 5,\r\n \"Location\": 4,\r\n \"Overall\": 4,\r\n \"Rooms\": 3,\r\n \"Service\": 5,\r\n \"Value\": 4\r\n }\r\n },\r\n {\r\n \"author\": \"fuzzy Snipes\",\r\n \"content\": \"blah\",\r\n \"date\": \"2013\u201306\u201322 18:33:50 +0300\",\r\n \"ratings\": {\r\n \"Cleanliness\": 2,\r\n \"Location\": 3,\r\n \"Overall\": 4,\r\n \"Rooms\": 3,\r\n \"Service\": 5,\r\n \"Value\": 4\r\n }\r\n }\r\n ]\r\n]\r\n<\/code><\/pre>\n<ul>\n<li>You can then use swift language features like <code>flatMap<\/code> and <code>map<\/code> to process the resulting array to derive the minimum \u201cCleanliness\u201d rating for given hotel<\/li>\n<\/ul>\n<pre class=\"wrap:true lang:swift decode:true \">let minCleanlinessValue = matches.flatMap{$0}\r\n .map{return ($0[\"ratings\"] as? [String:Any])?[\"Cleanliness\"] as? Int}\r\n .flatMap{$0}\r\n .min { (a, b) -&gt; Bool in\r\n      return a &lt; b\r\n }<\/pre>\n<p>You would do something similar in languages that support functional constructs like <code>flatmap<\/code> and <code>map<\/code>.<\/p>\n<h3 id=\"whatnext\">What Next<\/h3>\n<p>This blog post looked at how you can handle Array collection types using the new Query API in Couchbase Mobile 2.0. This is a start. Expect to see more functionality in future releases. You can download the Pre-release build from our <a href=\"https:\/\/developer.couchbase.com\/documentation\/mobile\/2.0\/whatsnew.html\">downloads<\/a> page.<\/p>\n<p>Here are other Couchbase Mobile Query related posts that may be of interest<br \/>\n&#8211; This <a href=\"https:\/\/www.couchbase.com\/blog\/sql-for-json-query-interface-couchbase-mobile\/\">blog post<\/a> discusses the fundamentals of the Query API<br \/>\n&#8211; This <a href=\"https:\/\/www.couchbase.com\/blog\/full-text-search-couchbase-mobile-2-0\/\">blog post<\/a> discusses the Full Text Search capabilities.<br \/>\n&#8211; This <a href=\"https:\/\/www.couchbase.com\/blog\/join-queries-couchbase-mobile\/\">blog post<\/a> discusses how to do JOIN queries<\/p>\n<p>If\u00a0you have questions or feedback, please leave a comment below or feel free to reach out to me at Twitter\u00a0<a href=\"https:\/\/twitter.com\/rajagp\">@rajagp<\/a>\u00a0or email me\u00a0<a href=\"mailto:priya.rajagopal@couchbase.com\">priya.rajagopal@couchbase.com<\/a>. \u00a0The\u00a0<a href=\"https:\/\/www.couchbase.com\/forums\/\">Couchbase Forums<\/a> are another good place to reach out with\u00a0questions.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>One of the major features introduced in Couchbase Lite 2.0, is the new Query interface based on N1QL, Couchbase\u2019s declarative query language that extends SQL for JSON. If you are familiar with SQL, you will feel right at home with [&hellip;]<\/p>\n","protected":false},"author":1423,"featured_media":4188,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"inline_featured_image":false,"footnotes":""},"categories":[1811,1815,7667,1810,1812],"tags":[1536,1909],"ppma_author":[8948],"class_list":["post-4410","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-dotnet","category-best-practices-and-tutorials","category-couchbase-lite","category-couchbase-mobile","category-n1ql-query","tag-ios","tag-swift"],"acf":[],"yoast_head":"<!-- This site is optimized with the Yoast SEO Premium plugin v25.9 (Yoast SEO v25.9) - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Query Array Collections in Couchbase Lite Using New API<\/title>\n<meta name=\"description\" content=\"In this Couchbase blog post, we will discuss array query collections conducted using Couchbase Lite, the new API query interface based on N1QL.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.couchbase.com\/blog\/querying-array-collections-couchbase-mobile\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"How to Query Array Collections in Couchbase Lite\" \/>\n<meta property=\"og:description\" content=\"In this Couchbase blog post, we will discuss array query collections conducted using Couchbase Lite, the new API query interface based on N1QL.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.couchbase.com\/blog\/querying-array-collections-couchbase-mobile\/\" \/>\n<meta property=\"og:site_name\" content=\"The Couchbase Blog\" \/>\n<meta property=\"article:published_time\" content=\"2018-01-03T18:28:26+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2025-06-14T03:09:25+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2017\/11\/feature_image.png\" \/>\n\t<meta property=\"og:image:width\" content=\"1716\" \/>\n\t<meta property=\"og:image:height\" content=\"842\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/png\" \/>\n<meta name=\"author\" content=\"Priya Rajagopal, Senior Director, Product Management\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@rajagp\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Priya Rajagopal, Senior Director, Product Management\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"8 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/www.couchbase.com\/blog\/querying-array-collections-couchbase-mobile\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/www.couchbase.com\/blog\/querying-array-collections-couchbase-mobile\/\"},\"author\":{\"name\":\"Priya Rajagopal, Senior Director, Product Management\",\"@id\":\"https:\/\/www.couchbase.com\/blog\/#\/schema\/person\/c2da90e57717ee4970c48a87a131ac2c\"},\"headline\":\"How to Query Array Collections in Couchbase Lite\",\"datePublished\":\"2018-01-03T18:28:26+00:00\",\"dateModified\":\"2025-06-14T03:09:25+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/www.couchbase.com\/blog\/querying-array-collections-couchbase-mobile\/\"},\"wordCount\":1333,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\/\/www.couchbase.com\/blog\/#organization\"},\"image\":{\"@id\":\"https:\/\/www.couchbase.com\/blog\/querying-array-collections-couchbase-mobile\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2017\/11\/feature_image.png\",\"keywords\":[\"ios\",\"swift\"],\"articleSection\":[\".NET\",\"Best Practices and Tutorials\",\"Couchbase Lite\",\"Couchbase Mobile\",\"SQL++ \/ N1QL Query\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\/\/www.couchbase.com\/blog\/querying-array-collections-couchbase-mobile\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.couchbase.com\/blog\/querying-array-collections-couchbase-mobile\/\",\"url\":\"https:\/\/www.couchbase.com\/blog\/querying-array-collections-couchbase-mobile\/\",\"name\":\"Query Array Collections in Couchbase Lite Using New API\",\"isPartOf\":{\"@id\":\"https:\/\/www.couchbase.com\/blog\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/www.couchbase.com\/blog\/querying-array-collections-couchbase-mobile\/#primaryimage\"},\"image\":{\"@id\":\"https:\/\/www.couchbase.com\/blog\/querying-array-collections-couchbase-mobile\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2017\/11\/feature_image.png\",\"datePublished\":\"2018-01-03T18:28:26+00:00\",\"dateModified\":\"2025-06-14T03:09:25+00:00\",\"description\":\"In this Couchbase blog post, we will discuss array query collections conducted using Couchbase Lite, the new API query interface based on N1QL.\",\"breadcrumb\":{\"@id\":\"https:\/\/www.couchbase.com\/blog\/querying-array-collections-couchbase-mobile\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.couchbase.com\/blog\/querying-array-collections-couchbase-mobile\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.couchbase.com\/blog\/querying-array-collections-couchbase-mobile\/#primaryimage\",\"url\":\"https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2017\/11\/feature_image.png\",\"contentUrl\":\"https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2017\/11\/feature_image.png\",\"width\":1716,\"height\":842,\"caption\":\"SQL for JSON Query\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.couchbase.com\/blog\/querying-array-collections-couchbase-mobile\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/www.couchbase.com\/blog\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"How to Query Array Collections in Couchbase Lite\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/www.couchbase.com\/blog\/#website\",\"url\":\"https:\/\/www.couchbase.com\/blog\/\",\"name\":\"The Couchbase Blog\",\"description\":\"Couchbase, the NoSQL Database\",\"publisher\":{\"@id\":\"https:\/\/www.couchbase.com\/blog\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/www.couchbase.com\/blog\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\/\/www.couchbase.com\/blog\/#organization\",\"name\":\"The Couchbase Blog\",\"url\":\"https:\/\/www.couchbase.com\/blog\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.couchbase.com\/blog\/#\/schema\/logo\/image\/\",\"url\":\"https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/2023\/04\/admin-logo.png\",\"contentUrl\":\"https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/2023\/04\/admin-logo.png\",\"width\":218,\"height\":34,\"caption\":\"The Couchbase Blog\"},\"image\":{\"@id\":\"https:\/\/www.couchbase.com\/blog\/#\/schema\/logo\/image\/\"}},{\"@type\":\"Person\",\"@id\":\"https:\/\/www.couchbase.com\/blog\/#\/schema\/person\/c2da90e57717ee4970c48a87a131ac2c\",\"name\":\"Priya Rajagopal, Senior Director, Product Management\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.couchbase.com\/blog\/#\/schema\/person\/image\/4b50a54778b979d8c345b036ab138734\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/acfb2349788955262cd069497a9e7bdb0e97c26326f2e55811e7c1174e9ef1be?s=96&d=mm&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/acfb2349788955262cd069497a9e7bdb0e97c26326f2e55811e7c1174e9ef1be?s=96&d=mm&r=g\",\"caption\":\"Priya Rajagopal, Senior Director, Product Management\"},\"description\":\"Priya Rajagopal is a Senior Director of Product Management at Couchbase responsible for developer platforms for the cloud and the edge. She has been professionally developing software for over 20 years in several technical and product leadership positions, with 10+ years focused on mobile technologies. As a TISPAN IPTV standards delegate, she was a key contributor to the IPTV standards specifications. She has 22 patents in the areas of networking and platform security.\",\"sameAs\":[\"https:\/\/x.com\/rajagp\"],\"url\":\"https:\/\/www.couchbase.com\/blog\/author\/priya-rajagopalcouchbase-com\/\"}]}<\/script>\n<!-- \/ Yoast SEO Premium plugin. -->","yoast_head_json":{"title":"Query Array Collections in Couchbase Lite Using New API","description":"In this Couchbase blog post, we will discuss array query collections conducted using Couchbase Lite, the new API query interface based on N1QL.","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.couchbase.com\/blog\/querying-array-collections-couchbase-mobile\/","og_locale":"en_US","og_type":"article","og_title":"How to Query Array Collections in Couchbase Lite","og_description":"In this Couchbase blog post, we will discuss array query collections conducted using Couchbase Lite, the new API query interface based on N1QL.","og_url":"https:\/\/www.couchbase.com\/blog\/querying-array-collections-couchbase-mobile\/","og_site_name":"The Couchbase Blog","article_published_time":"2018-01-03T18:28:26+00:00","article_modified_time":"2025-06-14T03:09:25+00:00","og_image":[{"width":1716,"height":842,"url":"https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2017\/11\/feature_image.png","type":"image\/png"}],"author":"Priya Rajagopal, Senior Director, Product Management","twitter_card":"summary_large_image","twitter_creator":"@rajagp","twitter_misc":{"Written by":"Priya Rajagopal, Senior Director, Product Management","Est. reading time":"8 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/www.couchbase.com\/blog\/querying-array-collections-couchbase-mobile\/#article","isPartOf":{"@id":"https:\/\/www.couchbase.com\/blog\/querying-array-collections-couchbase-mobile\/"},"author":{"name":"Priya Rajagopal, Senior Director, Product Management","@id":"https:\/\/www.couchbase.com\/blog\/#\/schema\/person\/c2da90e57717ee4970c48a87a131ac2c"},"headline":"How to Query Array Collections in Couchbase Lite","datePublished":"2018-01-03T18:28:26+00:00","dateModified":"2025-06-14T03:09:25+00:00","mainEntityOfPage":{"@id":"https:\/\/www.couchbase.com\/blog\/querying-array-collections-couchbase-mobile\/"},"wordCount":1333,"commentCount":0,"publisher":{"@id":"https:\/\/www.couchbase.com\/blog\/#organization"},"image":{"@id":"https:\/\/www.couchbase.com\/blog\/querying-array-collections-couchbase-mobile\/#primaryimage"},"thumbnailUrl":"https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2017\/11\/feature_image.png","keywords":["ios","swift"],"articleSection":[".NET","Best Practices and Tutorials","Couchbase Lite","Couchbase Mobile","SQL++ \/ N1QL Query"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/www.couchbase.com\/blog\/querying-array-collections-couchbase-mobile\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/www.couchbase.com\/blog\/querying-array-collections-couchbase-mobile\/","url":"https:\/\/www.couchbase.com\/blog\/querying-array-collections-couchbase-mobile\/","name":"Query Array Collections in Couchbase Lite Using New API","isPartOf":{"@id":"https:\/\/www.couchbase.com\/blog\/#website"},"primaryImageOfPage":{"@id":"https:\/\/www.couchbase.com\/blog\/querying-array-collections-couchbase-mobile\/#primaryimage"},"image":{"@id":"https:\/\/www.couchbase.com\/blog\/querying-array-collections-couchbase-mobile\/#primaryimage"},"thumbnailUrl":"https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2017\/11\/feature_image.png","datePublished":"2018-01-03T18:28:26+00:00","dateModified":"2025-06-14T03:09:25+00:00","description":"In this Couchbase blog post, we will discuss array query collections conducted using Couchbase Lite, the new API query interface based on N1QL.","breadcrumb":{"@id":"https:\/\/www.couchbase.com\/blog\/querying-array-collections-couchbase-mobile\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.couchbase.com\/blog\/querying-array-collections-couchbase-mobile\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.couchbase.com\/blog\/querying-array-collections-couchbase-mobile\/#primaryimage","url":"https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2017\/11\/feature_image.png","contentUrl":"https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2017\/11\/feature_image.png","width":1716,"height":842,"caption":"SQL for JSON Query"},{"@type":"BreadcrumbList","@id":"https:\/\/www.couchbase.com\/blog\/querying-array-collections-couchbase-mobile\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.couchbase.com\/blog\/"},{"@type":"ListItem","position":2,"name":"How to Query Array Collections in Couchbase Lite"}]},{"@type":"WebSite","@id":"https:\/\/www.couchbase.com\/blog\/#website","url":"https:\/\/www.couchbase.com\/blog\/","name":"The Couchbase Blog","description":"Couchbase, the NoSQL Database","publisher":{"@id":"https:\/\/www.couchbase.com\/blog\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.couchbase.com\/blog\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/www.couchbase.com\/blog\/#organization","name":"The Couchbase Blog","url":"https:\/\/www.couchbase.com\/blog\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.couchbase.com\/blog\/#\/schema\/logo\/image\/","url":"https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/2023\/04\/admin-logo.png","contentUrl":"https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/2023\/04\/admin-logo.png","width":218,"height":34,"caption":"The Couchbase Blog"},"image":{"@id":"https:\/\/www.couchbase.com\/blog\/#\/schema\/logo\/image\/"}},{"@type":"Person","@id":"https:\/\/www.couchbase.com\/blog\/#\/schema\/person\/c2da90e57717ee4970c48a87a131ac2c","name":"Priya Rajagopal, Senior Director, Product Management","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.couchbase.com\/blog\/#\/schema\/person\/image\/4b50a54778b979d8c345b036ab138734","url":"https:\/\/secure.gravatar.com\/avatar\/acfb2349788955262cd069497a9e7bdb0e97c26326f2e55811e7c1174e9ef1be?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/acfb2349788955262cd069497a9e7bdb0e97c26326f2e55811e7c1174e9ef1be?s=96&d=mm&r=g","caption":"Priya Rajagopal, Senior Director, Product Management"},"description":"Priya Rajagopal is a Senior Director of Product Management at Couchbase responsible for developer platforms for the cloud and the edge. She has been professionally developing software for over 20 years in several technical and product leadership positions, with 10+ years focused on mobile technologies. As a TISPAN IPTV standards delegate, she was a key contributor to the IPTV standards specifications. She has 22 patents in the areas of networking and platform security.","sameAs":["https:\/\/x.com\/rajagp"],"url":"https:\/\/www.couchbase.com\/blog\/author\/priya-rajagopalcouchbase-com\/"}]}},"authors":[{"term_id":8948,"user_id":1423,"is_guest":0,"slug":"priya-rajagopalcouchbase-com","display_name":"Priya Rajagopal, Senior Director, Product Management","avatar_url":"https:\/\/secure.gravatar.com\/avatar\/acfb2349788955262cd069497a9e7bdb0e97c26326f2e55811e7c1174e9ef1be?s=96&d=mm&r=g","author_category":"","last_name":"Rajagopal, Senior Director, Product Management","first_name":"Priya","job_title":"","user_url":"","description":"Priya Rajagopal is a Senior Director of Product Management at Couchbase responsible for developer platforms for the cloud and the edge. She has been professionally developing software for over 20 years in several technical and product leadership positions, with 10+ years focused on mobile technologies. As a TISPAN IPTV standards delegate, she was a key contributor to the IPTV standards specifications. She has 22 patents in the areas of networking and platform security."}],"_links":{"self":[{"href":"https:\/\/www.couchbase.com\/blog\/wp-json\/wp\/v2\/posts\/4410","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.couchbase.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.couchbase.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.couchbase.com\/blog\/wp-json\/wp\/v2\/users\/1423"}],"replies":[{"embeddable":true,"href":"https:\/\/www.couchbase.com\/blog\/wp-json\/wp\/v2\/comments?post=4410"}],"version-history":[{"count":0,"href":"https:\/\/www.couchbase.com\/blog\/wp-json\/wp\/v2\/posts\/4410\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.couchbase.com\/blog\/wp-json\/wp\/v2\/media\/4188"}],"wp:attachment":[{"href":"https:\/\/www.couchbase.com\/blog\/wp-json\/wp\/v2\/media?parent=4410"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.couchbase.com\/blog\/wp-json\/wp\/v2\/categories?post=4410"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.couchbase.com\/blog\/wp-json\/wp\/v2\/tags?post=4410"},{"taxonomy":"author","embeddable":true,"href":"https:\/\/www.couchbase.com\/blog\/wp-json\/wp\/v2\/ppma_author?post=4410"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}