{"id":13556,"date":"2022-07-13T10:09:45","date_gmt":"2022-07-13T17:09:45","guid":{"rendered":"https:\/\/www.couchbase.com\/blog\/?p=13556"},"modified":"2025-06-13T17:20:45","modified_gmt":"2025-06-14T00:20:45","slug":"from-n1ql-to-javascript-and-back-part-1-introduction","status":"publish","type":"post","link":"https:\/\/www.couchbase.com\/blog\/from-n1ql-to-javascript-and-back-part-1-introduction\/","title":{"rendered":"From N1QL to Javascript and Back &#8211; Part 1: Introduction"},"content":{"rendered":"<p><b>Among the many great features introduced in Couchbase Server 7.0<\/b><span style=\"font-weight: 400;\">, one has the potential for a greater impact in later releases: N1QL User Defined Functions.<\/span><\/p>\n<h2><span style=\"font-weight: 400;\">A quick glance at the past<\/span><\/h2>\n<p><span style=\"font-weight: 400;\">N1QL is a declarative language, meaning that requests merely indicate <\/span><i><span style=\"font-weight: 400;\">what<\/span><\/i><span style=\"font-weight: 400;\"> the user requires, without ever needing to specify <\/span><i><span style=\"font-weight: 400;\">how<\/span><\/i><span style=\"font-weight: 400;\"> the request should be carried out.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">This has worked very well for query languages, albeit with the limitation of the lack of bespoke business logic.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">User Defined Functions bridge that gap.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">The complete view of UDFs in Couchbase Server 7.0 is available in <\/span><a href=\"https:\/\/www.couchbase.com\/blog\/n1ql-user-defined-functions\/\" target=\"_blank\" rel=\"noopener\"><span style=\"font-weight: 400;\">this blog<\/span><\/a><span style=\"font-weight: 400;\">, but just to avoid jumping back and forth, a quick reminder of a few important things:<\/span><\/p>\n<ul>\n<li style=\"list-style-type: none;\">\n<ul>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><span style=\"font-weight: 400;\">UDFs come in several languages. In this blog we are particularly interested in JavaScript.<\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><span style=\"font-weight: 400;\">UDFs come in two flavours, cluster wide (or <\/span><i><span style=\"font-weight: 400;\">global<\/span><\/i><span style=\"font-weight: 400;\"> UDFs), useful when you haven&#8217;t yet embraced collections, and scope bound (or <\/span><i><span style=\"font-weight: 400;\">scope<\/span><\/i><span style=\"font-weight: 400;\"> UDFs), which allow you to have several copies of the same UDF (one per scope), but each with potentially different logic.<\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><span style=\"font-weight: 400;\">N1QL does not offer UDF overloading (having multiple UDFs with same name and different signature, each supporting logic specific to its input), but the same functionality can be achieved with variadic UDFs.<\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><span style=\"font-weight: 400;\">N1QL UDFs can generate dynamic data which can be used as a source to N1QL queries.<\/span><\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<h3><span style=\"font-weight: 400;\">JavaScript UDFs<\/span><\/h3>\n<ul>\n<li style=\"list-style-type: none;\">\n<ul>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><span style=\"font-weight: 400;\">JavaScript is an <\/span><i><span style=\"font-weight: 400;\">external<\/span><\/i><span style=\"font-weight: 400;\"> language, meaning that the management and execution of JavaScript libraries is delegated to an entity different from the N1QL service. This entity is called<\/span><i><span style=\"font-weight: 400;\"> jsevaluator.<\/span><\/i><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><span style=\"font-weight: 400;\">Creating JavaScript functions is a two step process: first you create the actual javascript code using the <\/span><i><span style=\"font-weight: 400;\">jsevaluator<\/span><\/i><span style=\"font-weight: 400;\"> interface, and then you create the N1QL UDF referencing it.<\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><span style=\"font-weight: 400;\">One of the side benefits of the code being maintained externally is that several UDFs can share the same library and thus the same code, and they all get updated at the same time when the code changes: shared libraries can go in step with your application, as opposed to the scope schema.<\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><span style=\"font-weight: 400;\">In the 7.0 release the <\/span><i><span style=\"font-weight: 400;\">jsevaluator<\/span><\/i><span style=\"font-weight: 400;\"> only supports plain JavaScript.<\/span><\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<h3><span style=\"font-weight: 400;\">The missing bits<\/span><\/h3>\n<p><span style=\"font-weight: 400;\">The jsevaluator does not support global states &#8211; since, as we have seen, the same library can be used by multiple requests concurrently across the query service: saving and retrieving values in global variables would lead to unexpected results.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">The side effect of this is that global arrow functions are not supported, as the function reference is saved in a global variable.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">Local arrow functions (those declared inside global function bodies) work as expected.<\/span><\/p>\n<h3><span style=\"font-weight: 400;\">An actual example<\/span><\/h3>\n<p><span style=\"font-weight: 400;\">First create the JavaScript library and function:<\/span><\/p>\n<pre class=\"decode-attributes:false lang:default decode:true\">curl -v -X POST https:\/\/localhost:8093\/evaluator\/v1\/libraries\/math \\\r\n     -u Administrator:password \\\r\n     -d 'function add(a, b) { let data = a + b; return data; }'<\/pre>\n<p><span style=\"font-weight: 400;\">Then create the N1QL UDF:<\/span><\/p>\n<pre class=\"decode-attributes:false lang:default decode:true \">cbq&gt; CREATE FUNCTION javascriptAdd(a, b) LANGUAGE javascript AS \"add\" AT \"math\";<\/pre>\n<p><span style=\"font-weight: 400;\">Note that it is perfectly legitimate to create the UDF first and the library later, but, until you create the library, you won&#8217;t be able to execute the UDF!<\/span><\/p>\n<h2><span style=\"font-weight: 400;\">New in 7.1!<\/span><\/h2>\n<h3><span style=\"font-weight: 400;\">User interface<\/span><\/h3>\n<p><span style=\"font-weight: 400;\">You no longer need to concern yourself with strange REST endpoint and curl commands to manipulate javascript libraries: the <em>Query<\/em> page has a new tab, <em>UDF<\/em>:<\/span><\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-large wp-image-13557\" src=\"https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/2022\/07\/new-couchbase-UDF-UI-console-1024x359.png\" alt=\"New UDF page in Couchbase UI\" width=\"900\" height=\"316\" srcset=\"https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2022\/07\/new-couchbase-UDF-UI-console-1024x359.png 1024w, https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2022\/07\/new-couchbase-UDF-UI-console-300x105.png 300w, https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2022\/07\/new-couchbase-UDF-UI-console-768x269.png 768w, https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2022\/07\/new-couchbase-UDF-UI-console-1536x538.png 1536w, https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2022\/07\/new-couchbase-UDF-UI-console-800x280.png 800w, https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2022\/07\/new-couchbase-UDF-UI-console-20x7.png 20w, https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2022\/07\/new-couchbase-UDF-UI-console-1320x462.png 1320w, https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2022\/07\/new-couchbase-UDF-UI-console.png 1999w\" sizes=\"auto, (max-width: 900px) 100vw, 900px\" \/><\/p>\n<p><span style=\"font-weight: 400;\">Upon clicking it lists are shown of JavaScript libraries and N1QL UDF definitions:<\/span><\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-large wp-image-13558\" src=\"https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/2022\/07\/image3-1-1024x340.png\" alt=\"Manage UDFs and JavaScript functions in UI\" width=\"900\" height=\"299\" srcset=\"https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2022\/07\/image3-1-1024x340.png 1024w, https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2022\/07\/image3-1-300x99.png 300w, https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2022\/07\/image3-1-768x255.png 768w, https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2022\/07\/image3-1-1536x509.png 1536w, https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2022\/07\/image3-1-20x7.png 20w, https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2022\/07\/image3-1-1320x438.png 1320w, https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2022\/07\/image3-1.png 1999w\" sizes=\"auto, (max-width: 900px) 100vw, 900px\" \/><\/p>\n<p><span style=\"font-weight: 400;\">There are buttons to add and edit both JavaScript libraries and N1QL User Defined Functions.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">The important thing to note is that Libraries are being edited or added, not individual functions: to add a new function to a JavaScript library, the whole library must be edited, and re-submitted with all the existing functions and the new function (submitting the new function alone will obliterate the existing functions, so do use care!).<\/span><\/p>\n<p><span style=\"font-weight: 400;\">Note that while there are plans to take the UDF JavaScript libraries UI to the same place where the Eventing UI is (e.g. with a debugger), we are not there yet, and the UI will likely change as a result, both in aspect and location.<\/span><\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-large wp-image-13559\" src=\"https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/2022\/07\/image2-1-1024x950.png\" alt=\"Add JavaScript library using UI\" width=\"900\" height=\"835\" srcset=\"https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2022\/07\/image2-1-1024x950.png 1024w, https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2022\/07\/image2-1-300x278.png 300w, https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2022\/07\/image2-1-768x712.png 768w, https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2022\/07\/image2-1-1536x1424.png 1536w, https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2022\/07\/image2-1-20x20.png 20w, https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2022\/07\/image2-1-1320x1224.png 1320w, https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2022\/07\/image2-1.png 1734w\" sizes=\"auto, (max-width: 900px) 100vw, 900px\" \/><\/p>\n<h3><span style=\"font-weight: 400;\">N1QL in JavaScript <\/span><\/h3>\n<p><span style=\"font-weight: 400;\">The JavaScript engine shipped with 7.0.x is only able to execute vanilla JavaScript, and lacks the ability to execute N1QL requests.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">In 7.1.x the JavaScript engine can now execute multiple N1QL statements and supports both iterators and transactions.<\/span><\/p>\n<h3><span style=\"font-weight: 400;\">Hierarchical JavaScript library storage<\/span><\/h3>\n<p><span style=\"font-weight: 400;\">In 7.0 the JavaScript library store is a flat repository, meaning that all the libraries sit at the same level, and are visible to both global and scope N1QL UDFs.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">These libraries are shared.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">In 7.1 the storage has been extended to be hierarchical.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">Root level libraries are still accessible to both global and scope N1QL UDFs and shared as before, and in addition it is now possible to have libraries defined under a specific bucket and scope, either as separate implementations of root level libraries specific to one particular scope, or as a private library storage for users with access to just one particular scope.<\/span><\/p>\n<p>&nbsp;<\/p>\n<h2><span style=\"font-weight: 400;\">Conclusion<\/span><\/h2>\n<p><span style=\"font-weight: 400;\">This blog gives you a taster of the JavaScript user defined functions features in Couchbase Server 7.1.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">We will explore each of them in detail in subsequent blogs.<\/span><\/p>\n<ul>\n<li style=\"list-style-type: none;\">\n<ul>\n<li>For now, read more about <a href=\"https:\/\/www.couchbase.com\/blog\/n1ql-user-defined-functions\/\" target=\"_blank\" rel=\"noopener\">N1QL UDFs in Couchbase<\/a><\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Among the many great features introduced in Couchbase Server 7.0, one has the potential for a greater impact in later releases: N1QL User Defined Functions. A quick glance at the past N1QL is a declarative language, meaning that requests merely [&hellip;]<\/p>\n","protected":false},"author":1782,"featured_media":11779,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"inline_featured_image":false,"footnotes":""},"categories":[1816,9327,1812],"tags":[2133,1543,8911],"ppma_author":[8924],"class_list":["post-13556","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-couchbase-server","category-javascript","category-n1ql-query","tag-functions","tag-javascript","tag-udf"],"acf":[],"yoast_head":"<!-- This site is optimized with the Yoast SEO Premium plugin v26.1 (Yoast SEO v26.1.1) - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>From N1QL to Javascript and Back - Part 1: Introduction<\/title>\n<meta name=\"description\" content=\"This blog gives you a taster of N1QL and the JavaScript User Defined Functions (UDF) features in Couchbase Server 7.1. Learn more with Couchbase.\" \/>\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\/from-n1ql-to-javascript-and-back-part-1-introduction\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"From N1QL to Javascript and Back - Part 1: Introduction\" \/>\n<meta property=\"og:description\" content=\"This blog gives you a taster of N1QL and the JavaScript User Defined Functions (UDF) features in Couchbase Server 7.1. Learn more with Couchbase.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.couchbase.com\/blog\/from-n1ql-to-javascript-and-back-part-1-introduction\/\" \/>\n<meta property=\"og:site_name\" content=\"The Couchbase Blog\" \/>\n<meta property=\"article:published_time\" content=\"2022-07-13T17:09:45+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2025-06-14T00:20:45+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2020\/12\/user-defined-functions-n1ql-query-language-couchbase-7-0.jpg\" \/>\n\t<meta property=\"og:image:width\" content=\"1200\" \/>\n\t<meta property=\"og:image:height\" content=\"628\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/jpeg\" \/>\n<meta name=\"author\" content=\"Marco Greco, Software Architect, Couchbase\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Marco Greco, Software Architect, Couchbase\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"5 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/www.couchbase.com\/blog\/from-n1ql-to-javascript-and-back-part-1-introduction\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/www.couchbase.com\/blog\/from-n1ql-to-javascript-and-back-part-1-introduction\/\"},\"author\":{\"name\":\"Marco Greco, Software Architect, Couchbase\",\"@id\":\"https:\/\/www.couchbase.com\/blog\/#\/schema\/person\/2b5184a7cdb443ff2897aff0866cd6fd\"},\"headline\":\"From N1QL to Javascript and Back &#8211; Part 1: Introduction\",\"datePublished\":\"2022-07-13T17:09:45+00:00\",\"dateModified\":\"2025-06-14T00:20:45+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/www.couchbase.com\/blog\/from-n1ql-to-javascript-and-back-part-1-introduction\/\"},\"wordCount\":833,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\/\/www.couchbase.com\/blog\/#organization\"},\"image\":{\"@id\":\"https:\/\/www.couchbase.com\/blog\/from-n1ql-to-javascript-and-back-part-1-introduction\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2020\/12\/user-defined-functions-n1ql-query-language-couchbase-7-0.jpg\",\"keywords\":[\"functions\",\"javascript\",\"User Defined Function (UDF)\"],\"articleSection\":[\"Couchbase Server\",\"JavaScript\",\"SQL++ \/ N1QL Query\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\/\/www.couchbase.com\/blog\/from-n1ql-to-javascript-and-back-part-1-introduction\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.couchbase.com\/blog\/from-n1ql-to-javascript-and-back-part-1-introduction\/\",\"url\":\"https:\/\/www.couchbase.com\/blog\/from-n1ql-to-javascript-and-back-part-1-introduction\/\",\"name\":\"From N1QL to Javascript and Back - Part 1: Introduction\",\"isPartOf\":{\"@id\":\"https:\/\/www.couchbase.com\/blog\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/www.couchbase.com\/blog\/from-n1ql-to-javascript-and-back-part-1-introduction\/#primaryimage\"},\"image\":{\"@id\":\"https:\/\/www.couchbase.com\/blog\/from-n1ql-to-javascript-and-back-part-1-introduction\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2020\/12\/user-defined-functions-n1ql-query-language-couchbase-7-0.jpg\",\"datePublished\":\"2022-07-13T17:09:45+00:00\",\"dateModified\":\"2025-06-14T00:20:45+00:00\",\"description\":\"This blog gives you a taster of N1QL and the JavaScript User Defined Functions (UDF) features in Couchbase Server 7.1. Learn more with Couchbase.\",\"breadcrumb\":{\"@id\":\"https:\/\/www.couchbase.com\/blog\/from-n1ql-to-javascript-and-back-part-1-introduction\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.couchbase.com\/blog\/from-n1ql-to-javascript-and-back-part-1-introduction\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.couchbase.com\/blog\/from-n1ql-to-javascript-and-back-part-1-introduction\/#primaryimage\",\"url\":\"https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2020\/12\/user-defined-functions-n1ql-query-language-couchbase-7-0.jpg\",\"contentUrl\":\"https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2020\/12\/user-defined-functions-n1ql-query-language-couchbase-7-0.jpg\",\"width\":1200,\"height\":628,\"caption\":\"Learn these tips and tricks for creating user-defined functions (UDFs) with the N1QL query language\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.couchbase.com\/blog\/from-n1ql-to-javascript-and-back-part-1-introduction\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/www.couchbase.com\/blog\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"From N1QL to Javascript and Back &#8211; Part 1: Introduction\"}]},{\"@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\/2b5184a7cdb443ff2897aff0866cd6fd\",\"name\":\"Marco Greco, Software Architect, Couchbase\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.couchbase.com\/blog\/#\/schema\/person\/image\/707c967b795fd71b6330f6d3118cf308\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/e6be0ee56851d2f71a554731d5edd5c820069680f0a810b47f094091c58bc553?s=96&d=mm&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/e6be0ee56851d2f71a554731d5edd5c820069680f0a810b47f094091c58bc553?s=96&d=mm&r=g\",\"caption\":\"Marco Greco, Software Architect, Couchbase\"},\"description\":\"In a previous life, Marco used to be CTO, radiation physicist, software architect, sysadmin, DBA, trainer and general handyman at Italy's largest radiation theraphy practice. Having switched career and country, he spent more than two decades in various support and development positions in Informix first and IBM later, before finally taking the plunge and joining Couchbase, to help them make gold out of N1QL. He holds several patents and has authored open source projects of his own.\",\"sameAs\":[\"https:\/\/github.com\/marcogrecopriolo\",\"https:\/\/www.linkedin.com\/in\/marco-greco-7665308\/\"],\"url\":\"https:\/\/www.couchbase.com\/blog\/author\/marcocouchbase-com\/\"}]}<\/script>\n<!-- \/ Yoast SEO Premium plugin. -->","yoast_head_json":{"title":"From N1QL to Javascript and Back - Part 1: Introduction","description":"This blog gives you a taster of N1QL and the JavaScript User Defined Functions (UDF) features in Couchbase Server 7.1. Learn more with Couchbase.","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\/from-n1ql-to-javascript-and-back-part-1-introduction\/","og_locale":"en_US","og_type":"article","og_title":"From N1QL to Javascript and Back - Part 1: Introduction","og_description":"This blog gives you a taster of N1QL and the JavaScript User Defined Functions (UDF) features in Couchbase Server 7.1. Learn more with Couchbase.","og_url":"https:\/\/www.couchbase.com\/blog\/from-n1ql-to-javascript-and-back-part-1-introduction\/","og_site_name":"The Couchbase Blog","article_published_time":"2022-07-13T17:09:45+00:00","article_modified_time":"2025-06-14T00:20:45+00:00","og_image":[{"width":1200,"height":628,"url":"https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2020\/12\/user-defined-functions-n1ql-query-language-couchbase-7-0.jpg","type":"image\/jpeg"}],"author":"Marco Greco, Software Architect, Couchbase","twitter_card":"summary_large_image","twitter_misc":{"Written by":"Marco Greco, Software Architect, Couchbase","Est. reading time":"5 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/www.couchbase.com\/blog\/from-n1ql-to-javascript-and-back-part-1-introduction\/#article","isPartOf":{"@id":"https:\/\/www.couchbase.com\/blog\/from-n1ql-to-javascript-and-back-part-1-introduction\/"},"author":{"name":"Marco Greco, Software Architect, Couchbase","@id":"https:\/\/www.couchbase.com\/blog\/#\/schema\/person\/2b5184a7cdb443ff2897aff0866cd6fd"},"headline":"From N1QL to Javascript and Back &#8211; Part 1: Introduction","datePublished":"2022-07-13T17:09:45+00:00","dateModified":"2025-06-14T00:20:45+00:00","mainEntityOfPage":{"@id":"https:\/\/www.couchbase.com\/blog\/from-n1ql-to-javascript-and-back-part-1-introduction\/"},"wordCount":833,"commentCount":0,"publisher":{"@id":"https:\/\/www.couchbase.com\/blog\/#organization"},"image":{"@id":"https:\/\/www.couchbase.com\/blog\/from-n1ql-to-javascript-and-back-part-1-introduction\/#primaryimage"},"thumbnailUrl":"https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2020\/12\/user-defined-functions-n1ql-query-language-couchbase-7-0.jpg","keywords":["functions","javascript","User Defined Function (UDF)"],"articleSection":["Couchbase Server","JavaScript","SQL++ \/ N1QL Query"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/www.couchbase.com\/blog\/from-n1ql-to-javascript-and-back-part-1-introduction\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/www.couchbase.com\/blog\/from-n1ql-to-javascript-and-back-part-1-introduction\/","url":"https:\/\/www.couchbase.com\/blog\/from-n1ql-to-javascript-and-back-part-1-introduction\/","name":"From N1QL to Javascript and Back - Part 1: Introduction","isPartOf":{"@id":"https:\/\/www.couchbase.com\/blog\/#website"},"primaryImageOfPage":{"@id":"https:\/\/www.couchbase.com\/blog\/from-n1ql-to-javascript-and-back-part-1-introduction\/#primaryimage"},"image":{"@id":"https:\/\/www.couchbase.com\/blog\/from-n1ql-to-javascript-and-back-part-1-introduction\/#primaryimage"},"thumbnailUrl":"https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2020\/12\/user-defined-functions-n1ql-query-language-couchbase-7-0.jpg","datePublished":"2022-07-13T17:09:45+00:00","dateModified":"2025-06-14T00:20:45+00:00","description":"This blog gives you a taster of N1QL and the JavaScript User Defined Functions (UDF) features in Couchbase Server 7.1. Learn more with Couchbase.","breadcrumb":{"@id":"https:\/\/www.couchbase.com\/blog\/from-n1ql-to-javascript-and-back-part-1-introduction\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.couchbase.com\/blog\/from-n1ql-to-javascript-and-back-part-1-introduction\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.couchbase.com\/blog\/from-n1ql-to-javascript-and-back-part-1-introduction\/#primaryimage","url":"https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2020\/12\/user-defined-functions-n1ql-query-language-couchbase-7-0.jpg","contentUrl":"https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2020\/12\/user-defined-functions-n1ql-query-language-couchbase-7-0.jpg","width":1200,"height":628,"caption":"Learn these tips and tricks for creating user-defined functions (UDFs) with the N1QL query language"},{"@type":"BreadcrumbList","@id":"https:\/\/www.couchbase.com\/blog\/from-n1ql-to-javascript-and-back-part-1-introduction\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.couchbase.com\/blog\/"},{"@type":"ListItem","position":2,"name":"From N1QL to Javascript and Back &#8211; Part 1: Introduction"}]},{"@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\/2b5184a7cdb443ff2897aff0866cd6fd","name":"Marco Greco, Software Architect, Couchbase","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.couchbase.com\/blog\/#\/schema\/person\/image\/707c967b795fd71b6330f6d3118cf308","url":"https:\/\/secure.gravatar.com\/avatar\/e6be0ee56851d2f71a554731d5edd5c820069680f0a810b47f094091c58bc553?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/e6be0ee56851d2f71a554731d5edd5c820069680f0a810b47f094091c58bc553?s=96&d=mm&r=g","caption":"Marco Greco, Software Architect, Couchbase"},"description":"In a previous life, Marco used to be CTO, radiation physicist, software architect, sysadmin, DBA, trainer and general handyman at Italy's largest radiation theraphy practice. Having switched career and country, he spent more than two decades in various support and development positions in Informix first and IBM later, before finally taking the plunge and joining Couchbase, to help them make gold out of N1QL. He holds several patents and has authored open source projects of his own.","sameAs":["https:\/\/github.com\/marcogrecopriolo","https:\/\/www.linkedin.com\/in\/marco-greco-7665308\/"],"url":"https:\/\/www.couchbase.com\/blog\/author\/marcocouchbase-com\/"}]}},"authors":[{"term_id":8924,"user_id":1782,"is_guest":0,"slug":"marcocouchbase-com","display_name":"Marco Greco, Software Architect, Couchbase","avatar_url":"https:\/\/secure.gravatar.com\/avatar\/e6be0ee56851d2f71a554731d5edd5c820069680f0a810b47f094091c58bc553?s=96&d=mm&r=g","author_category":"","last_name":"Greco","first_name":"Marco","job_title":"","user_url":"","description":"In a previous life, Marco used to be CTO, radiation physicist, software architect, sysadmin, DBA, trainer and general handyman at Italy's largest radiation theraphy practice.\r\n\r\nHaving switched career and country, he spent more than two decades in various support and development positions in Informix first and IBM later, before finally taking the plunge and joining Couchbase, to help them make gold out of N1QL.\r\n\r\nHe holds several patents and has authored open source projects of his own."}],"_links":{"self":[{"href":"https:\/\/www.couchbase.com\/blog\/wp-json\/wp\/v2\/posts\/13556","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\/1782"}],"replies":[{"embeddable":true,"href":"https:\/\/www.couchbase.com\/blog\/wp-json\/wp\/v2\/comments?post=13556"}],"version-history":[{"count":0,"href":"https:\/\/www.couchbase.com\/blog\/wp-json\/wp\/v2\/posts\/13556\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.couchbase.com\/blog\/wp-json\/wp\/v2\/media\/11779"}],"wp:attachment":[{"href":"https:\/\/www.couchbase.com\/blog\/wp-json\/wp\/v2\/media?parent=13556"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.couchbase.com\/blog\/wp-json\/wp\/v2\/categories?post=13556"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.couchbase.com\/blog\/wp-json\/wp\/v2\/tags?post=13556"},{"taxonomy":"author","embeddable":true,"href":"https:\/\/www.couchbase.com\/blog\/wp-json\/wp\/v2\/ppma_author?post=13556"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}