{"id":2326,"date":"2016-07-07T15:18:31","date_gmt":"2016-07-07T15:18:30","guid":{"rendered":"https:\/\/www.couchbase.com\/blog\/?p=2326"},"modified":"2025-06-13T21:09:44","modified_gmt":"2025-06-14T04:09:44","slug":"using-the-couchbase-sub-document-api-with-the-golang-sdk","status":"publish","type":"post","link":"https:\/\/www.couchbase.com\/blog\/pt\/using-the-couchbase-sub-document-api-with-the-golang-sdk\/","title":{"rendered":"Usando a API de subdocumento do Couchbase com o GoLang SDK"},"content":{"rendered":"<p>H\u00e1 pouco tempo, escrevi sobre como trabalhar com partes ou fragmentos de documentos no Couchbase<br \/>\n<a href=\"https:\/\/www.couchbase.com\/blog\/pt\/using-the-couchbase-sub-document-api-with-the-nodejs-sdk\/\">usando o SDK do Node.js<\/a>. Ser capaz de trabalhar com<br \/>\npartes de documentos \u00e9 poss\u00edvel usando<br \/>\n<a href=\"https:\/\/developer.couchbase.com\/server\/?utm_source=blogs&amp;utm_medium=link&amp;utm_campaign=blogs\">Servidor Couchbase<\/a> 4.5 e superior e a API do subdocumento.<br \/>\nIsso \u00e9 muito importante porque, ao trabalhar com documentos NoSQL, voc\u00ea pode se deparar com documentos muito grandes devido a todos os dados JSON incorporados. Como voc\u00ea provavelmente<br \/>\nSabe-se que fazer solicita\u00e7\u00f5es em documentos grandes \u00e9 lento e, na era moderna da Web, tudo precisa ser r\u00e1pido. Em vez disso, \u00e9 mais eficiente apenas<br \/>\nTrabalhe com o que voc\u00ea precisa e n\u00e3o com tudo de uma vez.<\/p>\n<p>Desta vez, vamos tentar fazer as mesmas manipula\u00e7\u00f5es de documentos NoSQL que vimos no Node.js, mas, desta vez, com a linguagem de programa\u00e7\u00e3o Go. Vamos l\u00e1<br \/>\ncriar uma hist\u00f3ria de dados para este exemplo. Ser\u00e1 a mesma hist\u00f3ria de dados do exemplo anterior, mas vamos supor que temos o seguinte documento JSON:<\/p>\n<pre><code>\r\n{\r\n    firstName: \"Nic\",\r\n    lastName: \"Raboy\",\r\n    socialNetworking: {\r\n        twitter: \"nraboy\"\r\n    }\r\n}\r\n<\/code><\/pre>\n<p>Os dados acima ser\u00e3o uma base <a href=\"https:\/\/www.couchbase.com\/blog\/pt\/user-profile-store-advanced-data-modeling\/\">armazenamento de perfil de usu\u00e1rio<\/a> com informa\u00e7\u00f5es de m\u00eddia social. Todas as nossas manipula\u00e7\u00f5es ser\u00e3o em torno das informa\u00e7\u00f5es de m\u00eddia social, n\u00e3o<br \/>\nos dados principais que o cercam.<\/p>\n<p>Para simplificar este guia, vamos trabalhar com um projeto novo. Neste ponto, presumiremos que voc\u00ea tenha o Couchbase Server 4.5+ e o<br \/>\nGoLang instalado e configurado em seu computador. Se voc\u00ea ainda n\u00e3o baixou o GoLang SDK para o Couchbase, execute o seguinte em seu comando<br \/>\nPrompt ou Terminal:<\/p>\n<pre><code>\r\ngo get github.com\/couchbase\/gocb\r\n<\/code><\/pre>\n<p>Todo o nosso projeto para este exemplo residir\u00e1 em um \u00fanico arquivo. Vamos nos referir a esse arquivo como <strong>main.go<\/strong> e pode residir em qualquer<br \/>\nO diret\u00f3rio do projeto Go que voc\u00ea quiser, desde que atenda aos requisitos da linguagem de programa\u00e7\u00e3o Go.<\/p>\n<p>Para come\u00e7ar, vamos criar um arquivo <code>principal<\/code> dentro do nosso projeto:<\/p>\n<pre><code>\r\nfunc main() {\r\n fmt.Println(\"Starting the app...\")\r\n cluster, _ := gocb.Connect(\"couchbase:\/\/localhost\")\r\n bucket, _ = cluster.OpenBucket(\"default\", \"\")\r\n person := Person{FirstName: \"Nic\", LastName: \"Raboy\", SocialNetworking: &amp;SocialNetworking{Twitter: \"nraboy\"}}\r\n createDocument(\"nraboy\", &amp;person)\r\n}\r\n<\/code><\/pre>\n<p>H\u00e1 alguns aspectos a serem observados no exemplo acima. Primeiro, estamos estabelecendo uma conex\u00e3o com um cluster do Couchbase em execu\u00e7\u00e3o local. Quando a conex\u00e3o tiver<br \/>\nestabelecido, abrimos o <code>padr\u00e3o<\/code> balde. Observe que estamos atribuindo apenas um valor \u00e0 vari\u00e1vel <code>balde<\/code> e n\u00e3o o define. Isso<br \/>\n\u00e9 porque vamos usar essa vari\u00e1vel globalmente e devemos defini-la fora do <code>principal<\/code> fun\u00e7\u00e3o. Com o balde aberto, vamos<br \/>\ncriar nossa estrutura de dados inicial. Essa estrutura de dados <code>Pessoa<\/code> \u00e9 definido abaixo:<\/p>\n<pre><code>\r\ntype Person struct {\r\n FirstName        string            `json:\"firstname,omitempty\"`\r\n LastName         string            `json:\"lastname,omitempty\"`\r\n SocialNetworking *SocialNetworking `json:\"socialNetworking,omitempty\"`\r\n}\r\n\r\ntype SocialNetworking struct {\r\n Twitter string `json:\"twitter,omitempty\"`\r\n Website string `json:\"website,omitempty\"`\r\n}\r\n<\/code><\/pre>\n<p>O <code>Pessoa<\/code> ter\u00e1 as informa\u00e7\u00f5es b\u00e1sicas do usu\u00e1rio e far\u00e1 refer\u00eancia a outra estrutura chamada <code>Redes sociais<\/code>. Ambos<br \/>\ns\u00e3o marcadas com nomes de propriedades JSON que devem ser exclu\u00eddas da impress\u00e3o se estiverem em branco.<\/p>\n<p>Voltando ao <code>principal<\/code> fun\u00e7\u00e3o. Observe que nosso novo objeto de pessoa n\u00e3o tem o website. Adicionaremos isso mais tarde. O primeiro<br \/>\nque chamamos na fun\u00e7\u00e3o <code>principal<\/code> \u00e9 chamada de fun\u00e7\u00e3o <code>createDocument<\/code> e ele adicionar\u00e1 nosso objeto ao banco de dados. Esta fun\u00e7\u00e3o<br \/>\n\u00e9 definido da seguinte forma:<\/p>\n<pre><code>\r\nfunc createDocument(documentId string, person *Person) {\r\n fmt.Println(\"Upserting a full document...\")\r\n _, error := bucket.Upsert(documentId, person, 0)\r\n if error != nil {\r\n  fmt.Println(error.Error())\r\n  return\r\n }\r\n getDocument(documentId)\r\n getSubDocument(documentId)\r\n}\r\n<\/code><\/pre>\n<p>Na fun\u00e7\u00e3o acima, ainda n\u00e3o estamos trabalhando com fragmentos de um documento. Primeiro, precisamos iniciar o exemplo com dados novos. Vamos inserir<br \/>\no documento inicial e, se n\u00e3o houver erros, chamaremos <code>getDocument<\/code> para validar sua cria\u00e7\u00e3o e, em seguida<br \/>\n<code>getSubDocument<\/code> para obter uma determinada parte do documento. O <code>getDocument<\/code> ser\u00e1 usada duas vezes neste aplicativo e a fun\u00e7\u00e3o<br \/>\nele se parece com o seguinte:<\/p>\n<pre><code>\r\nfunc getDocument(documentId string) {\r\n fmt.Println(\"Getting the full document by id...\")\r\n var person Person\r\n _, error := bucket.Get(documentId, &amp;person)\r\n if error != nil {\r\n  fmt.Println(error.Error())\r\n  return\r\n }\r\n jsonPerson, _ := json.Marshal(&amp;person)\r\n fmt.Println(string(jsonPerson))\r\n}\r\n<\/code><\/pre>\n<p>No exemplo acima <code>getDocument<\/code> estamos obtendo o documento inteiro com base no id, transformando-o em JSON e, em seguida, imprimindo-o. Essa fun\u00e7\u00e3o<br \/>\nnos leva ao <code>getSubDocument<\/code> conforme mostrado abaixo:<\/p>\n<pre><code>\r\nfunc getSubDocument(documentId string) {\r\n fmt.Println(\"Getting part of a document by id...\")\r\n fragment, error := bucket.LookupIn(documentId).Get(\"socialNetworking\").Execute()\r\n if error != nil {\r\n  fmt.Println(error.Error())\r\n  return\r\n }\r\n var socialNetworking SocialNetworking\r\n fragment.Content(\"socialNetworking\", &amp;socialNetworking)\r\n jsonSocialNetworking, _ := json.Marshal(&amp;socialNetworking)\r\n fmt.Println(string(jsonSocialNetworking))\r\n upsertSubDocument(documentId, \"thepolyglotdeveloper.com\")\r\n}\r\n<\/code><\/pre>\n<p>No exemplo acima <code>getSubDocument<\/code> estamos fazendo uma pesquisa em um documento para uma propriedade espec\u00edfica. \u00c9 aqui que come\u00e7amos a trabalhar com<br \/>\na API do subdocumento. A pesquisa que estamos realizando \u00e9 uma pesquisa para o <code>redes sociais<\/code> propriedade. Observe que estou me referindo ao JSON, n\u00e3o ao<br \/>\no <code>estrutura<\/code> nome. Quando tivermos o fragmento, podemos transform\u00e1-lo em JSON e depois imprimi-lo. O resultado deve ser semelhante a este:<\/p>\n<pre><code>\r\n{\r\n    \"twitter\": \"nraboy\"\r\n}\r\n<\/code><\/pre>\n<p>No final do <code>getSubDocument<\/code> fazemos uma chamada para uma fun\u00e7\u00e3o a ser criada em breve <code>upsertSubDocument<\/code> fun\u00e7\u00e3o. \u00c9 aqui que<br \/>\nvamos modificar parte de um documento sem antes obter o documento inteiro. Essa fun\u00e7\u00e3o pode ser vista da seguinte forma:<\/p>\n<pre><code>\r\nfunc upsertSubDocument(documentId string, website string) {\r\n fmt.Println(\"Upserting part of a document...\")\r\n _, error := bucket.MutateIn(documentId, 0, 0).Upsert(\"socialNetworking.website\", website, true).Execute()\r\n if error != nil {\r\n  fmt.Println(error.Error())\r\n  return\r\n }\r\n getDocument(documentId)\r\n}\r\n<\/code><\/pre>\n<p>Na fun\u00e7\u00e3o acima, primeiro especificamos qual documento queremos manipular com base no ID do documento. Em seguida, dizemos que queremos fazer um upsert em um<br \/>\ndeterminado caminho ou propriedade do documento. Neste exemplo, estamos dizendo que queremos inserir um <code>site<\/code> encontrada na propriedade<br \/>\n<code>redes sociais<\/code> pai. Observe que todo esse processo ocorre sem a obten\u00e7\u00e3o efetiva do documento.<\/p>\n<p>Quando terminarmos, faremos uma pesquisa completa do documento novamente para ver como ele se parece como um todo. Caso voc\u00ea precise que isso seja colocado em perspectiva, um<br \/>\nMelhor ainda, o c\u00f3digo completo desse projeto pode ser visto abaixo:<\/p>\n<pre><code>\r\npackage main\r\n\r\nimport (\r\n \"encoding\/json\"\r\n \"fmt\"\r\n\r\n \"github.com\/couchbase\/gocb\"\r\n)\r\n\r\nvar bucket *gocb.Bucket\r\n\r\ntype Person struct {\r\n FirstName        string            `json:\"firstname,omitempty\"`\r\n LastName         string            `json:\"lastname,omitempty\"`\r\n SocialNetworking *SocialNetworking `json:\"socialNetworking,omitempty\"`\r\n}\r\n\r\ntype SocialNetworking struct {\r\n Twitter string `json:\"twitter,omitempty\"`\r\n Website string `json:\"website,omitempty\"`\r\n}\r\n\r\nfunc getDocument(documentId string) {\r\n fmt.Println(\"Getting the full document by id...\")\r\n var person Person\r\n _, error := bucket.Get(documentId, &amp;person)\r\n if error != nil {\r\n  fmt.Println(error.Error())\r\n  return\r\n }\r\n jsonPerson, _ := json.Marshal(&amp;person)\r\n fmt.Println(string(jsonPerson))\r\n}\r\n\r\nfunc createDocument(documentId string, person *Person) {\r\n fmt.Println(\"Upserting a full document...\")\r\n _, error := bucket.Upsert(documentId, person, 0)\r\n if error != nil {\r\n  fmt.Println(error.Error())\r\n  return\r\n }\r\n getDocument(documentId)\r\n getSubDocument(documentId)\r\n}\r\n\r\nfunc getSubDocument(documentId string) {\r\n fmt.Println(\"Getting part of a document by id...\")\r\n fragment, error := bucket.LookupIn(documentId).Get(\"socialNetworking\").Execute()\r\n if error != nil {\r\n  fmt.Println(error.Error())\r\n  return\r\n }\r\n var socialNetworking SocialNetworking\r\n fragment.Content(\"socialNetworking\", &amp;socialNetworking)\r\n jsonSocialNetworking, _ := json.Marshal(&amp;socialNetworking)\r\n fmt.Println(string(jsonSocialNetworking))\r\n upsertSubDocument(documentId, \"thepolyglotdeveloper.com\")\r\n}\r\n\r\nfunc upsertSubDocument(documentId string, website string) {\r\n fmt.Println(\"Upserting part of a document...\")\r\n _, error := bucket.MutateIn(documentId, 0, 0).Upsert(\"socialNetworking.website\", website, true).Execute()\r\n if error != nil {\r\n  fmt.Println(error.Error())\r\n  return\r\n }\r\n getDocument(documentId)\r\n}\r\n\r\nfunc main() {\r\n fmt.Println(\"Starting the app...\")\r\n cluster, _ := gocb.Connect(\"couchbase:\/\/localhost\")\r\n bucket, _ = cluster.OpenBucket(\"default\", \"\")\r\n person := Person{FirstName: \"Nic\", LastName: \"Raboy\", SocialNetworking: &amp;SocialNetworking{Twitter: \"nraboy\"}}\r\n createDocument(\"nraboy\", &amp;person)\r\n}\r\n<\/code><\/pre>\n<p>Fa\u00e7a um test drive neste projeto para ver como a API de subdocumentos \u00e9 maravilhosa.<\/p>\n<h2>Conclus\u00e3o<\/h2>\n<p>Voc\u00ea acabou de ver como usar a API de subdocumento do Couchbase Server em um aplicativo GoLang usando o Couchbase Go SDK. Voc\u00ea n\u00e3o precisar\u00e1 mais se preocupar com<br \/>\npassando por seus documentos NoSQL potencialmente enormes, arruinando os tempos de resposta do aplicativo. Se voc\u00ea sabe que seus documentos s\u00e3o grandes ou se precisa apenas de<br \/>\nvoc\u00ea pode usar essa API.<\/p>\n<p>Para obter mais informa\u00e7\u00f5es, visite o site do Couchbase <a href=\"https:\/\/www.couchbase.com\/blog\/pt\/developers\/?utm_source=blogs&amp;utm_medium=link&amp;utm_campaign=blogs\">Portal do desenvolvedor<\/a>.<\/p>","protected":false},"excerpt":{"rendered":"<p>Not too long ago I wrote about working with parts, or fragments, of documents in Couchbase using the Node.js SDK. Being able to work with parts of documents is made possible using Couchbase Server 4.5 and higher and the sub-document [&hellip;]<\/p>\n","protected":false},"author":63,"featured_media":13873,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"inline_featured_image":false,"footnotes":""},"categories":[1816,1820],"tags":[1606],"ppma_author":[9032],"class_list":["post-2326","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-couchbase-server","category-golang","tag-sub-document"],"yoast_head":"<!-- This site is optimized with the Yoast SEO Premium plugin v27.3 (Yoast SEO v27.3) - https:\/\/yoast.com\/product\/yoast-seo-premium-wordpress\/ -->\n<title>Using the Couchbase Sub-Document API with the GoLang SDK - The Couchbase Blog<\/title>\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\/using-the-couchbase-sub-document-api-with-the-golang-sdk\/\" \/>\n<meta property=\"og:locale\" content=\"pt_BR\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Using the Couchbase Sub-Document API with the GoLang SDK\" \/>\n<meta property=\"og:description\" content=\"Not too long ago I wrote about working with parts, or fragments, of documents in Couchbase using the Node.js SDK. Being able to work with parts of documents is made possible using Couchbase Server 4.5 and higher and the sub-document [&hellip;]\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.couchbase.com\/blog\/pt\/using-the-couchbase-sub-document-api-with-the-golang-sdk\/\" \/>\n<meta property=\"og:site_name\" content=\"The Couchbase Blog\" \/>\n<meta property=\"article:author\" content=\"https:\/\/www.facebook.com\/thepolyglotdeveloper\" \/>\n<meta property=\"article:published_time\" content=\"2016-07-07T15:18:30+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2025-06-14T04:09:44+00:00\" \/>\n<meta name=\"author\" content=\"Nic Raboy, Developer Advocate, Couchbase\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@nraboy\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Nic Raboy, Developer Advocate, Couchbase\" \/>\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\":\"Article\",\"@id\":\"https:\\\/\\\/www.couchbase.com\\\/blog\\\/using-the-couchbase-sub-document-api-with-the-golang-sdk\\\/#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.couchbase.com\\\/blog\\\/using-the-couchbase-sub-document-api-with-the-golang-sdk\\\/\"},\"author\":{\"name\":\"Nic Raboy, Developer Advocate, Couchbase\",\"@id\":\"https:\\\/\\\/www.couchbase.com\\\/blog\\\/#\\\/schema\\\/person\\\/bb545ebe83bb2d12f91095811d0a72e1\"},\"headline\":\"Using the Couchbase Sub-Document API with the GoLang SDK\",\"datePublished\":\"2016-07-07T15:18:30+00:00\",\"dateModified\":\"2025-06-14T04:09:44+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/www.couchbase.com\\\/blog\\\/using-the-couchbase-sub-document-api-with-the-golang-sdk\\\/\"},\"wordCount\":889,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\\\/\\\/www.couchbase.com\\\/blog\\\/#organization\"},\"image\":{\"@id\":\"https:\\\/\\\/www.couchbase.com\\\/blog\\\/using-the-couchbase-sub-document-api-with-the-golang-sdk\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/www.couchbase.com\\\/blog\\\/wp-content\\\/uploads\\\/sites\\\/1\\\/2022\\\/11\\\/couchbase-nosql-dbaas.png\",\"keywords\":[\"sub-document\"],\"articleSection\":[\"Couchbase Server\",\"GoLang\"],\"inLanguage\":\"pt-BR\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\\\/\\\/www.couchbase.com\\\/blog\\\/using-the-couchbase-sub-document-api-with-the-golang-sdk\\\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/www.couchbase.com\\\/blog\\\/using-the-couchbase-sub-document-api-with-the-golang-sdk\\\/\",\"url\":\"https:\\\/\\\/www.couchbase.com\\\/blog\\\/using-the-couchbase-sub-document-api-with-the-golang-sdk\\\/\",\"name\":\"Using the Couchbase Sub-Document API with the GoLang SDK - The Couchbase Blog\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.couchbase.com\\\/blog\\\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\\\/\\\/www.couchbase.com\\\/blog\\\/using-the-couchbase-sub-document-api-with-the-golang-sdk\\\/#primaryimage\"},\"image\":{\"@id\":\"https:\\\/\\\/www.couchbase.com\\\/blog\\\/using-the-couchbase-sub-document-api-with-the-golang-sdk\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/www.couchbase.com\\\/blog\\\/wp-content\\\/uploads\\\/sites\\\/1\\\/2022\\\/11\\\/couchbase-nosql-dbaas.png\",\"datePublished\":\"2016-07-07T15:18:30+00:00\",\"dateModified\":\"2025-06-14T04:09:44+00:00\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/www.couchbase.com\\\/blog\\\/using-the-couchbase-sub-document-api-with-the-golang-sdk\\\/#breadcrumb\"},\"inLanguage\":\"pt-BR\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/www.couchbase.com\\\/blog\\\/using-the-couchbase-sub-document-api-with-the-golang-sdk\\\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"pt-BR\",\"@id\":\"https:\\\/\\\/www.couchbase.com\\\/blog\\\/using-the-couchbase-sub-document-api-with-the-golang-sdk\\\/#primaryimage\",\"url\":\"https:\\\/\\\/www.couchbase.com\\\/blog\\\/wp-content\\\/uploads\\\/sites\\\/1\\\/2022\\\/11\\\/couchbase-nosql-dbaas.png\",\"contentUrl\":\"https:\\\/\\\/www.couchbase.com\\\/blog\\\/wp-content\\\/uploads\\\/sites\\\/1\\\/2022\\\/11\\\/couchbase-nosql-dbaas.png\",\"width\":1800,\"height\":630},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/www.couchbase.com\\\/blog\\\/using-the-couchbase-sub-document-api-with-the-golang-sdk\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/www.couchbase.com\\\/blog\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Using the Couchbase Sub-Document API with the GoLang SDK\"}]},{\"@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\\\/bb545ebe83bb2d12f91095811d0a72e1\",\"name\":\"Nic Raboy, Developer Advocate, Couchbase\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"pt-BR\",\"@id\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/bedeb68368d4681aca4c74fe5f697f0c423b80d498ec50fd915ba018b72c101f?s=96&d=mm&r=g8863514d8bed0cf6080f23db40e00354\",\"url\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/bedeb68368d4681aca4c74fe5f697f0c423b80d498ec50fd915ba018b72c101f?s=96&d=mm&r=g\",\"contentUrl\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/bedeb68368d4681aca4c74fe5f697f0c423b80d498ec50fd915ba018b72c101f?s=96&d=mm&r=g\",\"caption\":\"Nic Raboy, Developer Advocate, Couchbase\"},\"description\":\"Nic Raboy is an advocate of modern web and mobile development technologies. He has experience in Java, JavaScript, Golang and a variety of frameworks such as Angular, NativeScript, and Apache Cordova. Nic writes about his development experiences related to making web and mobile development easier to understand.\",\"sameAs\":[\"https:\\\/\\\/www.thepolyglotdeveloper.com\",\"https:\\\/\\\/www.facebook.com\\\/thepolyglotdeveloper\",\"https:\\\/\\\/x.com\\\/nraboy\"],\"url\":\"https:\\\/\\\/www.couchbase.com\\\/blog\\\/pt\\\/author\\\/nic-raboy-2\\\/\"}]}<\/script>\n<!-- \/ Yoast SEO Premium plugin. -->","yoast_head_json":{"title":"Using the Couchbase Sub-Document API with the GoLang SDK - The Couchbase Blog","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\/using-the-couchbase-sub-document-api-with-the-golang-sdk\/","og_locale":"pt_BR","og_type":"article","og_title":"Using the Couchbase Sub-Document API with the GoLang SDK","og_description":"Not too long ago I wrote about working with parts, or fragments, of documents in Couchbase using the Node.js SDK. Being able to work with parts of documents is made possible using Couchbase Server 4.5 and higher and the sub-document [&hellip;]","og_url":"https:\/\/www.couchbase.com\/blog\/pt\/using-the-couchbase-sub-document-api-with-the-golang-sdk\/","og_site_name":"The Couchbase Blog","article_author":"https:\/\/www.facebook.com\/thepolyglotdeveloper","article_published_time":"2016-07-07T15:18:30+00:00","article_modified_time":"2025-06-14T04:09:44+00:00","author":"Nic Raboy, Developer Advocate, Couchbase","twitter_card":"summary_large_image","twitter_creator":"@nraboy","twitter_misc":{"Written by":"Nic Raboy, Developer Advocate, Couchbase","Est. reading time":"4 minutos"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/www.couchbase.com\/blog\/using-the-couchbase-sub-document-api-with-the-golang-sdk\/#article","isPartOf":{"@id":"https:\/\/www.couchbase.com\/blog\/using-the-couchbase-sub-document-api-with-the-golang-sdk\/"},"author":{"name":"Nic Raboy, Developer Advocate, Couchbase","@id":"https:\/\/www.couchbase.com\/blog\/#\/schema\/person\/bb545ebe83bb2d12f91095811d0a72e1"},"headline":"Using the Couchbase Sub-Document API with the GoLang SDK","datePublished":"2016-07-07T15:18:30+00:00","dateModified":"2025-06-14T04:09:44+00:00","mainEntityOfPage":{"@id":"https:\/\/www.couchbase.com\/blog\/using-the-couchbase-sub-document-api-with-the-golang-sdk\/"},"wordCount":889,"commentCount":0,"publisher":{"@id":"https:\/\/www.couchbase.com\/blog\/#organization"},"image":{"@id":"https:\/\/www.couchbase.com\/blog\/using-the-couchbase-sub-document-api-with-the-golang-sdk\/#primaryimage"},"thumbnailUrl":"https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2022\/11\/couchbase-nosql-dbaas.png","keywords":["sub-document"],"articleSection":["Couchbase Server","GoLang"],"inLanguage":"pt-BR","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/www.couchbase.com\/blog\/using-the-couchbase-sub-document-api-with-the-golang-sdk\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/www.couchbase.com\/blog\/using-the-couchbase-sub-document-api-with-the-golang-sdk\/","url":"https:\/\/www.couchbase.com\/blog\/using-the-couchbase-sub-document-api-with-the-golang-sdk\/","name":"Using the Couchbase Sub-Document API with the GoLang SDK - The Couchbase Blog","isPartOf":{"@id":"https:\/\/www.couchbase.com\/blog\/#website"},"primaryImageOfPage":{"@id":"https:\/\/www.couchbase.com\/blog\/using-the-couchbase-sub-document-api-with-the-golang-sdk\/#primaryimage"},"image":{"@id":"https:\/\/www.couchbase.com\/blog\/using-the-couchbase-sub-document-api-with-the-golang-sdk\/#primaryimage"},"thumbnailUrl":"https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2022\/11\/couchbase-nosql-dbaas.png","datePublished":"2016-07-07T15:18:30+00:00","dateModified":"2025-06-14T04:09:44+00:00","breadcrumb":{"@id":"https:\/\/www.couchbase.com\/blog\/using-the-couchbase-sub-document-api-with-the-golang-sdk\/#breadcrumb"},"inLanguage":"pt-BR","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.couchbase.com\/blog\/using-the-couchbase-sub-document-api-with-the-golang-sdk\/"]}]},{"@type":"ImageObject","inLanguage":"pt-BR","@id":"https:\/\/www.couchbase.com\/blog\/using-the-couchbase-sub-document-api-with-the-golang-sdk\/#primaryimage","url":"https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2022\/11\/couchbase-nosql-dbaas.png","contentUrl":"https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2022\/11\/couchbase-nosql-dbaas.png","width":1800,"height":630},{"@type":"BreadcrumbList","@id":"https:\/\/www.couchbase.com\/blog\/using-the-couchbase-sub-document-api-with-the-golang-sdk\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.couchbase.com\/blog\/"},{"@type":"ListItem","position":2,"name":"Using the Couchbase Sub-Document API with the GoLang SDK"}]},{"@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\/bb545ebe83bb2d12f91095811d0a72e1","name":"Nic Raboy, defensor dos desenvolvedores, Couchbase","image":{"@type":"ImageObject","inLanguage":"pt-BR","@id":"https:\/\/secure.gravatar.com\/avatar\/bedeb68368d4681aca4c74fe5f697f0c423b80d498ec50fd915ba018b72c101f?s=96&d=mm&r=g8863514d8bed0cf6080f23db40e00354","url":"https:\/\/secure.gravatar.com\/avatar\/bedeb68368d4681aca4c74fe5f697f0c423b80d498ec50fd915ba018b72c101f?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/bedeb68368d4681aca4c74fe5f697f0c423b80d498ec50fd915ba018b72c101f?s=96&d=mm&r=g","caption":"Nic Raboy, Developer Advocate, Couchbase"},"description":"Nic Raboy \u00e9 um defensor das modernas tecnologias de desenvolvimento m\u00f3vel e da Web. Ele tem experi\u00eancia em Java, JavaScript, Golang e uma variedade de estruturas, como Angular, NativeScript e Apache Cordova. Nic escreve sobre suas experi\u00eancias de desenvolvimento relacionadas a tornar o desenvolvimento m\u00f3vel e da Web mais f\u00e1cil de entender.","sameAs":["https:\/\/www.thepolyglotdeveloper.com","https:\/\/www.facebook.com\/thepolyglotdeveloper","https:\/\/x.com\/nraboy"],"url":"https:\/\/www.couchbase.com\/blog\/pt\/author\/nic-raboy-2\/"}]}},"acf":[],"authors":[{"term_id":9032,"user_id":63,"is_guest":0,"slug":"nic-raboy-2","display_name":"Nic Raboy, Developer Advocate, Couchbase","avatar_url":"https:\/\/secure.gravatar.com\/avatar\/bedeb68368d4681aca4c74fe5f697f0c423b80d498ec50fd915ba018b72c101f?s=96&d=mm&r=g","0":null,"1":"","2":"","3":"","4":"","5":"","6":"","7":"","8":""}],"_links":{"self":[{"href":"https:\/\/www.couchbase.com\/blog\/pt\/wp-json\/wp\/v2\/posts\/2326","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\/63"}],"replies":[{"embeddable":true,"href":"https:\/\/www.couchbase.com\/blog\/pt\/wp-json\/wp\/v2\/comments?post=2326"}],"version-history":[{"count":0,"href":"https:\/\/www.couchbase.com\/blog\/pt\/wp-json\/wp\/v2\/posts\/2326\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.couchbase.com\/blog\/pt\/wp-json\/wp\/v2\/media\/13873"}],"wp:attachment":[{"href":"https:\/\/www.couchbase.com\/blog\/pt\/wp-json\/wp\/v2\/media?parent=2326"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.couchbase.com\/blog\/pt\/wp-json\/wp\/v2\/categories?post=2326"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.couchbase.com\/blog\/pt\/wp-json\/wp\/v2\/tags?post=2326"},{"taxonomy":"author","embeddable":true,"href":"https:\/\/www.couchbase.com\/blog\/pt\/wp-json\/wp\/v2\/ppma_author?post=2326"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}