{"id":11715,"date":"2021-08-30T00:00:47","date_gmt":"2021-08-30T07:00:47","guid":{"rendered":"https:\/\/www.couchbase.com\/blog\/?p=11715"},"modified":"2025-06-13T21:23:01","modified_gmt":"2025-06-14T04:23:01","slug":"how-to-create-nodejs-async-get-upsert-calls-with-couchbase","status":"publish","type":"post","link":"https:\/\/www.couchbase.com\/blog\/pt\/how-to-create-nodejs-async-get-upsert-calls-with-couchbase\/","title":{"rendered":"Como criar chamadas Get\/Upsert ass\u00edncronas com o Node.js e o Couchbase"},"content":{"rendered":"<p><strong>Se voc\u00ea \u00e9 um desenvolvedor de JavaScript que est\u00e1<\/strong> Ao fazer a transi\u00e7\u00e3o para o uso do Node.js, voc\u00ea vai querer aproveitar as vantagens das fun\u00e7\u00f5es ass\u00edncronas.<\/p>\n<p>Isso ocorre porque as chamadas de API ass\u00edncronas n\u00e3o bloqueiam seu c\u00f3digo e retornam promessas. Nesta publica\u00e7\u00e3o, mostrarei como criar fun\u00e7\u00f5es ass\u00edncronas no Node.js que chamam o SDK do Couchbase.<\/p>\n<h2>Recapitula\u00e7\u00e3o r\u00e1pida: Configurando um projeto Node.js com o Couchbase<\/h2>\n<p>Esta postagem d\u00e1 continuidade \u00e0 minha s\u00e9rie introdut\u00f3ria sobre <a href=\"https:\/\/developer.couchbase.com\/topic\/nodejs?ref=blog\" target=\"_blank\" rel=\"noopener\">Usando o Node.js com o Couchbase<\/a>.<\/p>\n<p>Uma empresa existente <a href=\"https:\/\/www.couchbase.com\/blog\/pt\/products\/capella\/\" target=\"_blank\" rel=\"noopener\">Couchbase<\/a> banco de dados (com <code>amostra de viagem<\/code> Bucket ativado) e <a href=\"https:\/\/nodejs.org\/en\/?ref=hello-from-couchbase\" target=\"_blank\" rel=\"noopener\">Node.js<\/a> \u00e9 considerado para este tutorial, mas para obter mais detalhes <a href=\"https:\/\/www.couchbase.com\/blog\/pt\/get-started-nodejs-sdk-couchbase\/?ref=blog\" target=\"_blank\" rel=\"noopener\">veja a postagem da semana passada sobre como come\u00e7ar a usar o SDK do Node.js para o Couchbase<\/a>.<\/p>\n<p>Para atualiz\u00e1-lo, primeiro <a href=\"https:\/\/docs.couchbase.com\/nodejs-sdk\/current\/hello-world\/start-using-sdk.html?ref=blog\" target=\"_blank\" rel=\"noopener\">instalar o SDK do Couchbase Node.js<\/a> usando o <code>npm<\/code> juntamente com o comando <code>salvar<\/code> para armazenar a depend\u00eancia em seu <code>package.json<\/code> arquivo de configura\u00e7\u00e3o. Veja como isso se parece:<\/p>\n<pre>cd cb-node2\r\nnpm init -y\r\nnpm install couchbase --save\r\n<\/pre>\n<div class=\"wp-block-spacer\" style=\"height: 15px\" aria-hidden=\"true\"><\/div>\n<p>Agora voc\u00ea est\u00e1 pronto para passar para a pr\u00f3xima etapa.<\/p>\n<h2>Conectar-se ao Couchbase com uma fun\u00e7\u00e3o ass\u00edncrona<\/h2>\n<p>Connecting to Couchbase using the JavaScript `async` function requires you to import the library in addition to three more components:<\/p>\n<ul>\n<li style=\"list-style-type: none\">\n<ul>\n<li>Nome\/endere\u00e7o do servidor<\/li>\n<li>Nome de usu\u00e1rio\/senha<\/li>\n<li>O Bucket ao qual se conectar<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<div class=\"wp-block-spacer\" style=\"height: 15px\" aria-hidden=\"true\"><\/div>\n<p>Embrulhe tudo com um <code>ass\u00edncrono<\/code> e criar a fun\u00e7\u00e3o <code>agrupamento<\/code> objeto.<\/p>\n<pre>const couchbase = require(\"couchbase\")\r\n\r\nasync function main(){\r\n  const cluster = new couchbase.Cluster(\"couchbase:\/\/localhost\", {\r\n    username: \"Administrator\",\r\n    password: \"Administrator\"\r\n});\r\n<\/pre>\n<div class=\"wp-block-spacer\" style=\"height: 15px\" aria-hidden=\"true\"><\/div>\n<p>Depois de fornecer as principais informa\u00e7\u00f5es de conex\u00e3o, selecione o Bucket e qualquer escopo ou cole\u00e7\u00e3o espec\u00edfica (usei a cole\u00e7\u00e3o padr\u00e3o neste exemplo). O resultado <code>Cole\u00e7\u00e3o<\/code> \u00e9 usado para chamadas subsequentes ao banco de dados.<\/p>\n<pre>const bucket = cluster.bucket(\"travel-sample\");\r\nconst collection = bucket.defaultCollection();\r\n<\/pre>\n<div class=\"wp-block-spacer\" style=\"height: 15px\" aria-hidden=\"true\"><\/div>\n<h2>Obtendo um documento JSON<\/h2>\n<p>Now that you have an async function set up, let&#8217;s learn how you can `get` a <a href=\"https:\/\/www.couchbase.com\/blog\/pt\/json-database\/?ref=blog\" target=\"_blank\" rel=\"noopener\">Documento JSON<\/a> do Couchbase.<\/p>\n<p>Para concluir uma opera\u00e7\u00e3o b\u00e1sica de valor-chave, voc\u00ea precisa conhecer um ID de documento existente. Para este exemplo, vamos usar o ID do Chalets Marmotte Mountain Adventure na Fran\u00e7a: <code>hotel_5336<\/code>.<\/p>\n<p>The basic `get` syntax \u2013 shown in <a href=\"https:\/\/www.couchbase.com\/blog\/pt\/get-started-nodejs-sdk-couchbase\/?ref=blog\" target=\"_blank\" rel=\"noopener\">postagem anterior do blog tamb\u00e9m<\/a> - \u00e9:<\/p>\n<pre>collection.get(key)\r\n<\/pre>\n<div class=\"wp-block-spacer\" style=\"height: 15px\" aria-hidden=\"true\"><\/div>\n<p>Para torn\u00e1-lo ass\u00edncrono, use o <code>aguardar<\/code> dentro de uma palavra-chave <code>ass\u00edncrono<\/code> function. Chamaremos essa fun\u00e7\u00e3o posteriormente com nosso ID do hotel. Tamb\u00e9m \u00e9 um bom h\u00e1bito come\u00e7ar a capturar e imprimir todos os erros.<\/p>\n<pre>const getHotel = async (key) =&gt; {\r\n  try {\r\n    const result = await collection.get(key);\r\n    console.log(\"Result:\");\r\n    console.log(result);\r\n  } catch (error) {\r\n    console.error(error);\r\n  }\r\n};\r\n<\/pre>\n<div class=\"wp-block-spacer\" style=\"height: 15px\" aria-hidden=\"true\"><\/div>\n<p>Chame sua nova fun\u00e7\u00e3o no final do script. Lembre-se de que todo o script deve ser mantido dentro do diret\u00f3rio <code>principal()<\/code> que voc\u00ea chama:<\/p>\n<pre class=\"\">...\r\nawait getHotel(\"hotel_5336\");\r\n}\r\n\r\nmain();\r\n<\/pre>\n<div class=\"wp-block-spacer\" style=\"height: 15px\" aria-hidden=\"true\"><\/div>\n<p>Em seguida, teste sua fun\u00e7\u00e3o ass\u00edncrona executando e vendo a sa\u00edda para esse documento espec\u00edfico:<\/p>\n<pre class=\"\">$ node app.js\r\nResult:\r\nGetResult {\r\n  content:\r\n   { title: 'Chamonix',\r\n     name: 'Chalets Marmotte Mountain Adventure',\r\n     address: '31 chemin des Rambles, Argentiere',\r\n     directions: null,\r\n     phone: '+33682891523',\r\n<\/pre>\n<div class=\"wp-block-spacer\" style=\"height: 15px\" aria-hidden=\"true\"><\/div>\n<h2>Inser\u00e7\u00e3o ascendente de um documento JSON<\/h2>\n<p>Next, let&#8217;s cover how you can `upsert` a JSON document using your async function.<\/p>\n<p>Usando seu script original, voc\u00ea pode adicionar a capacidade de criar um novo documento e, em seguida, solicit\u00e1-lo de volta - para mostrar a viagem completa. Para salvar ou adicionar um documento ao banco de dados, use o comando <code>upsert<\/code> e passar a ele um objeto JSON.<\/p>\n<p>Lembre-se de que voc\u00ea pode manter a conex\u00e3o e <code>obter<\/code> e criar uma nova fun\u00e7\u00e3o para a fun\u00e7\u00e3o <code>upsert<\/code>.<\/p>\n<p>Primeiro, crie o <code>novoHotel<\/code> fun\u00e7\u00e3o. Como voc\u00ea pode ver abaixo, n\u00f3s a configuramos para receber a chave\/ID e um objeto JSON.<\/p>\n<pre>  const newHotel = async (key,jsondoc) =&gt; {\r\n    try {\r\n      const upresult = await collection.upsert(key, jsondoc);\r\n      console.log(\"\\nUpsert result:\");\r\n      console.log(upresult);\r\n    } catch (error){\r\n      console.error(error);\r\n    }\r\n  };\r\n<\/pre>\n<div class=\"wp-block-spacer\" style=\"height: 15px\" aria-hidden=\"true\"><\/div>\n<p>Em seguida, crie o documento JSON que enviaremos ao banco de dados do Couchbase.<\/p>\n<pre>  jsondoc = {\r\n    \"type\": \"hotel\",\r\n    \"id\": 3,\r\n    \"name\": \"Le Grande\",\r\n    \"city\": \"Paris, France\"\r\n  }\r\n<\/pre>\n<div class=\"wp-block-spacer\" style=\"height: 15px\" aria-hidden=\"true\"><\/div>\n<p>Chamaremos a nova entrada do hotel de <code>hotel_3<\/code> ao chamar a nova fun\u00e7\u00e3o:<\/p>\n<pre>  await newHotel(\"hotel_3\", jsondoc);\r\n<\/pre>\n<div class=\"wp-block-spacer\" style=\"height: 15px\" aria-hidden=\"true\"><\/div>\n<p>Se voc\u00ea colocar todo esse c\u00f3digo antes do <code>getHotel<\/code> voc\u00ea pode ajustar o ID do documento para a chamada <code>obter<\/code> para verificar se o novo hotel foi salvo.<\/p>\n<p>Aqui est\u00e1 o resultado da cria\u00e7\u00e3o do documento e da obten\u00e7\u00e3o do mesmo documento de volta:<\/p>\n<pre>$ node app.js\r\n\r\nUpsert result:\r\nMutationResult {\r\n  cas: CbCas&lt;1629156064638664704&gt;,\r\n  token: CbMutationToken&lt;771:243978275681931:85:travel-sample&gt; }\r\n(node:3060577) [DEP0079] DeprecationWarning: Custom inspection function on Objects via .inspect() is deprecated\r\n\r\nResult:\r\nGetResult {\r\n  content:\r\n   { type: 'hotel', id: 3, name: 'Le Grande', city: 'Paris, France' },\r\n  cas: CbCas&lt;1629156064638664704&gt;,\r\n  expiryTime: undefined }\r\n<\/pre>\n<div class=\"wp-block-spacer\" style=\"height: 15px\" aria-hidden=\"true\"><\/div>\n<h2>Exemplo de c\u00f3digo completo<\/h2>\n<p>Aqui est\u00e1 todo o c\u00f3digo de exemplo reunido na postagem de hoje:<\/p>\n<pre>const couchbase = require(\"couchbase\")\r\n\r\nasync function main(){\r\n  const cluster = new couchbase.Cluster(\"couchbase:\/\/localhost\", {\r\n    username: \"Administrator\",\r\n    password: \"Administrator\"\r\n  });\r\n\r\n\r\n  const bucket = cluster.bucket(\"travel-sample\");\r\n  const collection = bucket.defaultCollection();\r\n\r\n\r\n  const getHotel = async (key) =&gt; {\r\n    try {\r\n      const result = await collection.get(key);\r\n      console.log(\"\\nResult:\");\r\n      console.log(result);\r\n    } catch (error){\r\n      console.error(error);\r\n    }\r\n  };\r\n\r\n  const newHotel = async (key,jsondoc) =&gt; {\r\n    try {\r\n      const upresult = await collection.upsert(key, jsondoc);\r\n      console.log(\"\\nUpsert result:\");\r\n      console.log(upresult);\r\n    } catch (error){\r\n      console.error(error);\r\n    }\r\n  };\r\n\r\n  jsondoc = {\r\n    \"type\": \"hotel\",\r\n    \"id\": 3,\r\n    \"name\": \"Le Grande\",\r\n    \"city\": \"Paris, France\"\r\n  }\r\n\r\n  await newHotel(\"hotel_3\", jsondoc);\r\n\r\n  await getHotel(\"hotel_3\");\r\n\r\n}\r\n\r\nmain();\r\n<\/pre>\n<div class=\"wp-block-spacer\" style=\"height: 15px\" aria-hidden=\"true\"><\/div>\n<h2>Conclus\u00e3o<\/h2>\n<p>Parab\u00e9ns por ter feito um curso completo <code>upsert<\/code> e <code>obter<\/code> no Node.js! Agora voc\u00ea est\u00e1 pronto para criar um aplicativo mais complicado, que abordarei em futuras publica\u00e7\u00f5es no blog.<\/p>\n<p>Para obter um guia do desenvolvedor mais detalhado, consulte o <a target=\"_blank\" rel=\"noopener\">Documenta\u00e7\u00e3o do SDK do Couchbase Node.js aqui<\/a>.<\/p>\n<p><em>Fique por dentro do restante da s\u00e9rie de instru\u00e7\u00f5es sobre Node.js + Couchbase:<\/em><\/p>\n<ul>\n<li style=\"list-style-type: none\">\n<ul>\n<li><a href=\"https:\/\/www.couchbase.com\/blog\/pt\/get-started-nodejs-sdk-couchbase\/?ref=blog\" target=\"_blank\" rel=\"noopener\">Como come\u00e7ar a usar o SDK do Node.js para o Couchbase<\/a><\/li>\n<li><a href=\"https:\/\/www.couchbase.com\/blog\/pt\/how-to-create-nodejs-async-get-upsert-calls-with-couchbase\/?ref=blog\" target=\"_blank\" rel=\"noopener\">Como criar chamadas Get\/Upsert ass\u00edncronas com o Node.js e o Couchbase<\/a><\/li>\n<li><a href=\"https:\/\/www.couchbase.com\/blog\/pt\/build-a-rest-api-with-node-js-express-and-couchbase\/?ref=blog\" target=\"_blank\" rel=\"noopener\">Crie um aplicativo baseado em REST com Node.js, Express e Couchbase<\/a><\/li>\n<li><a href=\"https:\/\/www.couchbase.com\/blog\/pt\/how-to-query-json-data-n1ql-node-js-couchbase\/?ref=blog\" target=\"_blank\" rel=\"noopener\">Como consultar dados JSON usando N1QL para Node.js e Couchbase<\/a><\/li>\n<li><a href=\"https:\/\/www.couchbase.com\/blog\/pt\/how-to-full-text-search-javascript-app\/?ref=blog\" target=\"_blank\" rel=\"noopener\">Como adicionar a funcionalidade de pesquisa de texto completo ao seu aplicativo JavaScript<\/a><\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<p>&nbsp;<\/p>\n<div class=\"wp-block-spacer\" style=\"height: 30px\" aria-hidden=\"true\"><\/div>\n<div style=\"text-align: center\"><strong>Arregace as mangas e experimente voc\u00ea mesmo:<br \/>\n<a href=\"https:\/\/cloud.couchbase.com\/sign-up?ref=blog\" target=\"_blank\" rel=\"noopener\">Experimente o Couchbase Cloud hoje mesmo<\/a><\/strong><\/div>\n<div class=\"wp-block-spacer\" style=\"height: 15px\" aria-hidden=\"true\"><\/div>\n<p>&nbsp;<\/p>","protected":false},"excerpt":{"rendered":"<p>If you&#8217;re a JavaScript dev who&#8217;s transitioning to use Node.js, you&#8217;ll want to take advantage of async functions. That&#8217;s because asynchronous API calls don&#8217;t block your code and return promises. In this post, I&#8217;ll show you how to create async [&hellip;]<\/p>","protected":false},"author":75185,"featured_media":11812,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"inline_featured_image":false,"footnotes":""},"categories":[1815,9327,1822,2201],"tags":[9400,6311,1543,1261,2313,9317],"ppma_author":[9163],"class_list":["post-11715","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-best-practices-and-tutorials","category-javascript","category-node-js","category-tools-sdks","tag-async-function","tag-couchbase-cloud","tag-javascript","tag-json","tag-key-value","tag-upsert"],"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>Create Async Get\/Upsert Calls with Node.js and Couchbase<\/title>\n<meta name=\"description\" content=\"All JavaScript devs will want to take advantage of async functions. Find out how to create async functions in Node.js that will call the Couchbase SDK.\" \/>\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\/pt\/how-to-create-nodejs-async-get-upsert-calls-with-couchbase\/\" \/>\n<meta property=\"og:locale\" content=\"pt_BR\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"How to Create Async Get\/Upsert Calls with Node.js and Couchbase\" \/>\n<meta property=\"og:description\" content=\"All JavaScript devs will want to take advantage of async functions. Find out how to create async functions in Node.js that will call the Couchbase SDK.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.couchbase.com\/blog\/pt\/how-to-create-nodejs-async-get-upsert-calls-with-couchbase\/\" \/>\n<meta property=\"og:site_name\" content=\"The Couchbase Blog\" \/>\n<meta property=\"article:published_time\" content=\"2021-08-30T07:00:47+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2025-06-14T04:23:01+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2021\/08\/how-to-nodejs-async-functions-get-upsert-calls-couchbase-social.jpg\" \/>\n\t<meta property=\"og:image:width\" content=\"800\" \/>\n\t<meta property=\"og:image:height\" content=\"418\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/jpeg\" \/>\n<meta name=\"author\" content=\"Tyler Mitchell - Senior Product Marketing Manager\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:image\" content=\"https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2021\/08\/how-to-nodejs-async-functions-get-upsert-calls-couchbase-social.jpg\" \/>\n<meta name=\"twitter:creator\" content=\"@1tylermitchell\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Tyler Mitchell - Senior Product Marketing Manager\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"4 minutos\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"TechArticle\",\"@id\":\"https:\/\/www.couchbase.com\/blog\/how-to-create-nodejs-async-get-upsert-calls-with-couchbase\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/www.couchbase.com\/blog\/how-to-create-nodejs-async-get-upsert-calls-with-couchbase\/\"},\"author\":{\"name\":\"Tyler Mitchell - Senior Product Marketing Manager\",\"@id\":\"https:\/\/www.couchbase.com\/blog\/#\/schema\/person\/684cc0e5c60cd2e4b591db9621494ed0\"},\"headline\":\"How to Create Async Get\/Upsert Calls with Node.js and Couchbase\",\"datePublished\":\"2021-08-30T07:00:47+00:00\",\"dateModified\":\"2025-06-14T04:23:01+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/www.couchbase.com\/blog\/how-to-create-nodejs-async-get-upsert-calls-with-couchbase\/\"},\"wordCount\":694,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\/\/www.couchbase.com\/blog\/#organization\"},\"image\":{\"@id\":\"https:\/\/www.couchbase.com\/blog\/how-to-create-nodejs-async-get-upsert-calls-with-couchbase\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2021\/08\/how-to-nodejs-async-functions-get-upsert-calls-couchbase.jpg\",\"keywords\":[\"async function\",\"Couchbase Cloud\",\"javascript\",\"JSON\",\"key value\",\"upsert\"],\"articleSection\":[\"Best Practices and Tutorials\",\"JavaScript\",\"Node.js\",\"Tools &amp; SDKs\"],\"inLanguage\":\"pt-BR\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\/\/www.couchbase.com\/blog\/how-to-create-nodejs-async-get-upsert-calls-with-couchbase\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.couchbase.com\/blog\/how-to-create-nodejs-async-get-upsert-calls-with-couchbase\/\",\"url\":\"https:\/\/www.couchbase.com\/blog\/how-to-create-nodejs-async-get-upsert-calls-with-couchbase\/\",\"name\":\"Create Async Get\/Upsert Calls with Node.js and Couchbase\",\"isPartOf\":{\"@id\":\"https:\/\/www.couchbase.com\/blog\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/www.couchbase.com\/blog\/how-to-create-nodejs-async-get-upsert-calls-with-couchbase\/#primaryimage\"},\"image\":{\"@id\":\"https:\/\/www.couchbase.com\/blog\/how-to-create-nodejs-async-get-upsert-calls-with-couchbase\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2021\/08\/how-to-nodejs-async-functions-get-upsert-calls-couchbase.jpg\",\"datePublished\":\"2021-08-30T07:00:47+00:00\",\"dateModified\":\"2025-06-14T04:23:01+00:00\",\"description\":\"All JavaScript devs will want to take advantage of async functions. Find out how to create async functions in Node.js that will call the Couchbase SDK.\",\"breadcrumb\":{\"@id\":\"https:\/\/www.couchbase.com\/blog\/how-to-create-nodejs-async-get-upsert-calls-with-couchbase\/#breadcrumb\"},\"inLanguage\":\"pt-BR\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.couchbase.com\/blog\/how-to-create-nodejs-async-get-upsert-calls-with-couchbase\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"pt-BR\",\"@id\":\"https:\/\/www.couchbase.com\/blog\/how-to-create-nodejs-async-get-upsert-calls-with-couchbase\/#primaryimage\",\"url\":\"https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2021\/08\/how-to-nodejs-async-functions-get-upsert-calls-couchbase.jpg\",\"contentUrl\":\"https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2021\/08\/how-to-nodejs-async-functions-get-upsert-calls-couchbase.jpg\",\"width\":1200,\"height\":628,\"caption\":\"Learn how to create async functions like get and upsert by using the Node.js SDK for Couchbase\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.couchbase.com\/blog\/how-to-create-nodejs-async-get-upsert-calls-with-couchbase\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/www.couchbase.com\/blog\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"How to Create Async Get\/Upsert Calls with Node.js and Couchbase\"}]},{\"@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\":\"pt-BR\"},{\"@type\":\"Organization\",\"@id\":\"https:\/\/www.couchbase.com\/blog\/#organization\",\"name\":\"The Couchbase Blog\",\"url\":\"https:\/\/www.couchbase.com\/blog\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"pt-BR\",\"@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\/684cc0e5c60cd2e4b591db9621494ed0\",\"name\":\"Tyler Mitchell - Senior Product Marketing Manager\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"pt-BR\",\"@id\":\"https:\/\/www.couchbase.com\/blog\/#\/schema\/person\/image\/d8a7c532bf2b94b7a2fe7a8439aafd75\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/ebec3213e756f2e1f7118fcb5722e2cd1484c9256ae34ceb8f77054b986f21ce?s=96&d=mm&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/ebec3213e756f2e1f7118fcb5722e2cd1484c9256ae34ceb8f77054b986f21ce?s=96&d=mm&r=g\",\"caption\":\"Tyler Mitchell - Senior Product Marketing Manager\"},\"description\":\"Works as Senior Product Marketing Manager at Couchbase, helping bring knowledge about products into the public limelight while also supporting our field teams with valuable content.\",\"sameAs\":[\"https:\/\/linkedin.com\/in\/tylermitchell\",\"https:\/\/x.com\/1tylermitchell\",\"https:\/\/www.youtube.com\/channel\/UCBZFuoiTcg0f3lGSQwLjeTg\"],\"url\":\"https:\/\/www.couchbase.com\/blog\/pt\/author\/tylermitchell\/\"}]}<\/script>\n<!-- \/ Yoast SEO Premium plugin. -->","yoast_head_json":{"title":"Create Async Get\/Upsert Calls with Node.js and Couchbase","description":"Todos os desenvolvedores de JavaScript v\u00e3o querer aproveitar as vantagens das fun\u00e7\u00f5es ass\u00edncronas. Descubra como criar fun\u00e7\u00f5es ass\u00edncronas no Node.js que chamar\u00e3o o SDK do 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\/pt\/how-to-create-nodejs-async-get-upsert-calls-with-couchbase\/","og_locale":"pt_BR","og_type":"article","og_title":"How to Create Async Get\/Upsert Calls with Node.js and Couchbase","og_description":"All JavaScript devs will want to take advantage of async functions. Find out how to create async functions in Node.js that will call the Couchbase SDK.","og_url":"https:\/\/www.couchbase.com\/blog\/pt\/how-to-create-nodejs-async-get-upsert-calls-with-couchbase\/","og_site_name":"The Couchbase Blog","article_published_time":"2021-08-30T07:00:47+00:00","article_modified_time":"2025-06-14T04:23:01+00:00","og_image":[{"width":800,"height":418,"url":"https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2021\/08\/how-to-nodejs-async-functions-get-upsert-calls-couchbase-social.jpg","type":"image\/jpeg"}],"author":"Tyler Mitchell - Senior Product Marketing Manager","twitter_card":"summary_large_image","twitter_image":"https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2021\/08\/how-to-nodejs-async-functions-get-upsert-calls-couchbase-social.jpg","twitter_creator":"@1tylermitchell","twitter_misc":{"Written by":"Tyler Mitchell - Senior Product Marketing Manager","Est. reading time":"4 minutos"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"TechArticle","@id":"https:\/\/www.couchbase.com\/blog\/how-to-create-nodejs-async-get-upsert-calls-with-couchbase\/#article","isPartOf":{"@id":"https:\/\/www.couchbase.com\/blog\/how-to-create-nodejs-async-get-upsert-calls-with-couchbase\/"},"author":{"name":"Tyler Mitchell - Senior Product Marketing Manager","@id":"https:\/\/www.couchbase.com\/blog\/#\/schema\/person\/684cc0e5c60cd2e4b591db9621494ed0"},"headline":"How to Create Async Get\/Upsert Calls with Node.js and Couchbase","datePublished":"2021-08-30T07:00:47+00:00","dateModified":"2025-06-14T04:23:01+00:00","mainEntityOfPage":{"@id":"https:\/\/www.couchbase.com\/blog\/how-to-create-nodejs-async-get-upsert-calls-with-couchbase\/"},"wordCount":694,"commentCount":0,"publisher":{"@id":"https:\/\/www.couchbase.com\/blog\/#organization"},"image":{"@id":"https:\/\/www.couchbase.com\/blog\/how-to-create-nodejs-async-get-upsert-calls-with-couchbase\/#primaryimage"},"thumbnailUrl":"https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2021\/08\/how-to-nodejs-async-functions-get-upsert-calls-couchbase.jpg","keywords":["async function","Couchbase Cloud","javascript","JSON","key value","upsert"],"articleSection":["Best Practices and Tutorials","JavaScript","Node.js","Tools &amp; SDKs"],"inLanguage":"pt-BR","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/www.couchbase.com\/blog\/how-to-create-nodejs-async-get-upsert-calls-with-couchbase\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/www.couchbase.com\/blog\/how-to-create-nodejs-async-get-upsert-calls-with-couchbase\/","url":"https:\/\/www.couchbase.com\/blog\/how-to-create-nodejs-async-get-upsert-calls-with-couchbase\/","name":"Create Async Get\/Upsert Calls with Node.js and Couchbase","isPartOf":{"@id":"https:\/\/www.couchbase.com\/blog\/#website"},"primaryImageOfPage":{"@id":"https:\/\/www.couchbase.com\/blog\/how-to-create-nodejs-async-get-upsert-calls-with-couchbase\/#primaryimage"},"image":{"@id":"https:\/\/www.couchbase.com\/blog\/how-to-create-nodejs-async-get-upsert-calls-with-couchbase\/#primaryimage"},"thumbnailUrl":"https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2021\/08\/how-to-nodejs-async-functions-get-upsert-calls-couchbase.jpg","datePublished":"2021-08-30T07:00:47+00:00","dateModified":"2025-06-14T04:23:01+00:00","description":"Todos os desenvolvedores de JavaScript v\u00e3o querer aproveitar as vantagens das fun\u00e7\u00f5es ass\u00edncronas. Descubra como criar fun\u00e7\u00f5es ass\u00edncronas no Node.js que chamar\u00e3o o SDK do Couchbase.","breadcrumb":{"@id":"https:\/\/www.couchbase.com\/blog\/how-to-create-nodejs-async-get-upsert-calls-with-couchbase\/#breadcrumb"},"inLanguage":"pt-BR","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.couchbase.com\/blog\/how-to-create-nodejs-async-get-upsert-calls-with-couchbase\/"]}]},{"@type":"ImageObject","inLanguage":"pt-BR","@id":"https:\/\/www.couchbase.com\/blog\/how-to-create-nodejs-async-get-upsert-calls-with-couchbase\/#primaryimage","url":"https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2021\/08\/how-to-nodejs-async-functions-get-upsert-calls-couchbase.jpg","contentUrl":"https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2021\/08\/how-to-nodejs-async-functions-get-upsert-calls-couchbase.jpg","width":1200,"height":628,"caption":"Learn how to create async functions like get and upsert by using the Node.js SDK for Couchbase"},{"@type":"BreadcrumbList","@id":"https:\/\/www.couchbase.com\/blog\/how-to-create-nodejs-async-get-upsert-calls-with-couchbase\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.couchbase.com\/blog\/"},{"@type":"ListItem","position":2,"name":"How to Create Async Get\/Upsert Calls with Node.js and Couchbase"}]},{"@type":"WebSite","@id":"https:\/\/www.couchbase.com\/blog\/#website","url":"https:\/\/www.couchbase.com\/blog\/","name":"Blog do Couchbase","description":"Couchbase, o banco de dados NoSQL","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":"pt-BR"},{"@type":"Organization","@id":"https:\/\/www.couchbase.com\/blog\/#organization","name":"Blog do Couchbase","url":"https:\/\/www.couchbase.com\/blog\/","logo":{"@type":"ImageObject","inLanguage":"pt-BR","@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\/684cc0e5c60cd2e4b591db9621494ed0","name":"Tyler Mitchell - Gerente s\u00eanior de marketing de produtos","image":{"@type":"ImageObject","inLanguage":"pt-BR","@id":"https:\/\/www.couchbase.com\/blog\/#\/schema\/person\/image\/d8a7c532bf2b94b7a2fe7a8439aafd75","url":"https:\/\/secure.gravatar.com\/avatar\/ebec3213e756f2e1f7118fcb5722e2cd1484c9256ae34ceb8f77054b986f21ce?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/ebec3213e756f2e1f7118fcb5722e2cd1484c9256ae34ceb8f77054b986f21ce?s=96&d=mm&r=g","caption":"Tyler Mitchell - Senior Product Marketing Manager"},"description":"Works as Senior Product Marketing Manager at Couchbase, helping bring knowledge about products into the public limelight while also supporting our field teams with valuable content.","sameAs":["https:\/\/linkedin.com\/in\/tylermitchell","https:\/\/x.com\/1tylermitchell","https:\/\/www.youtube.com\/channel\/UCBZFuoiTcg0f3lGSQwLjeTg"],"url":"https:\/\/www.couchbase.com\/blog\/pt\/author\/tylermitchell\/"}]}},"authors":[{"term_id":9163,"user_id":75185,"is_guest":0,"slug":"tylermitchell","display_name":"Tyler Mitchell - Senior Product Marketing Manager","avatar_url":"https:\/\/secure.gravatar.com\/avatar\/876da1e4284f1832c871b3514caf7867357744b8c0a370ef6f53a79dee2f379e?s=96&d=mm&r=g","author_category":"","last_name":"Mitchell - Senior Product Marketing Manager","first_name":"Tyler","job_title":"Senior Product Marketing Manager","user_url":"","description":"Trabalha como Gerente S\u00eanior de Marketing de Produto na Couchbase, ajudando a levar o conhecimento sobre os produtos para o centro das aten\u00e7\u00f5es do p\u00fablico e, ao mesmo tempo, apoiando nossas equipes de campo com conte\u00fado valioso. Sua paix\u00e3o pessoal s\u00e3o todas as coisas geoespaciais, tendo trabalhado em GIS durante metade de sua carreira. Agora, a IA e a pesquisa vetorial est\u00e3o em sua mente."}],"_links":{"self":[{"href":"https:\/\/www.couchbase.com\/blog\/pt\/wp-json\/wp\/v2\/posts\/11715","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.couchbase.com\/blog\/pt\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.couchbase.com\/blog\/pt\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.couchbase.com\/blog\/pt\/wp-json\/wp\/v2\/users\/75185"}],"replies":[{"embeddable":true,"href":"https:\/\/www.couchbase.com\/blog\/pt\/wp-json\/wp\/v2\/comments?post=11715"}],"version-history":[{"count":0,"href":"https:\/\/www.couchbase.com\/blog\/pt\/wp-json\/wp\/v2\/posts\/11715\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.couchbase.com\/blog\/pt\/wp-json\/wp\/v2\/media\/11812"}],"wp:attachment":[{"href":"https:\/\/www.couchbase.com\/blog\/pt\/wp-json\/wp\/v2\/media?parent=11715"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.couchbase.com\/blog\/pt\/wp-json\/wp\/v2\/categories?post=11715"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.couchbase.com\/blog\/pt\/wp-json\/wp\/v2\/tags?post=11715"},{"taxonomy":"author","embeddable":true,"href":"https:\/\/www.couchbase.com\/blog\/pt\/wp-json\/wp\/v2\/ppma_author?post=11715"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}