{"id":11531,"date":"2021-07-20T03:47:56","date_gmt":"2021-07-20T10:47:56","guid":{"rendered":"https:\/\/www.couchbase.com\/blog\/?p=11531"},"modified":"2024-08-30T02:55:10","modified_gmt":"2024-08-30T09:55:10","slug":"using-java-sdk-for-couchbase-basics-get-upsert","status":"publish","type":"post","link":"https:\/\/www.couchbase.com\/blog\/using-java-sdk-for-couchbase-basics-get-upsert\/","title":{"rendered":"Using the Java SDK for Couchbase: The Basics of Get &amp; Upsert"},"content":{"rendered":"<p><strong>Using Java with Couchbase doesn&#8217;t have to be hard,<\/strong> even for a new developer.<\/p>\n<p>In this quickstart tutorial, we&#8217;re going to walk through the basics of creating and fetching JSON documents in Couchbase <a href=\"https:\/\/developer.couchbase.com\/topic\/java\/?ref=blog\" target=\"_blank\" rel=\"noopener\">using the Java SDK<\/a>. With minimalist code samples, you can be connecting and testing your application right away.<\/p>\n<h2>Set Up a Basic Java Application<\/h2>\n<p>Before you get started, make sure you have <a href=\"https:\/\/www.couchbase.com\/downloads\/?ref=blog\" target=\"_blank\" rel=\"noopener\">the most recent version of Couchbase installed<\/a>, along with the travel-sample bucket.<\/p>\n<p>Naturally, we need a basic Java development environment too. To set up a development environment on a new computer, consider using the <a href=\"https:\/\/code.visualstudio.com\/docs\/java\/java-tutorial\">Coding Pack for Java<\/a> from Microsoft.<\/p>\n<p>This package is handy because it helps install the JDK along with supporting extensions for the Visual Studio Code environment. I used OpenJDK 11 for my configuration and set it as my main <code>JAVA_HOME<\/code> once I downloaded it with their GUI.<\/p>\n<p>The Java Tools get started page was helpful to create a new project, select Maven build tools and specify a project folder. I select all the default values and the Maven project is automatically created under the <code>JAVA PROJECTS<\/code> file explorer and called demo.<\/p>\n<p>Open the <code>demo -&gt; src\/main\/java -&gt; com.example -&gt; App<\/code> file.<\/p>\n<p>Run a test build to ensure Java is configured properly, using the Play button at the top right of the editor. The output terminal window should show:<\/p>\n<p><code>Hello World!<\/code><\/p>\n<p>That confirms that Java is running properly and that your environment is ready to go.<\/p>\n<h2>Couchbase java-client Dependency for Maven<\/h2>\n<p>Add the Couchbase <code>java-client<\/code> dependency from <code>com.couchbase.client<\/code>, version 3.1.6 as a Maven dependency in the <code>pom.xml<\/code> file.<\/p>\n<p>If using a GUI to do this, be careful to get <code>java-client<\/code> and not <code>couchbase-client<\/code> libraries.<\/p>\n<pre>    \r\n      com.couchbase.client\r\n      java-client\r\n      3.1.6\r\n    \r\n<\/pre>\n<div class=\"wp-block-spacer\" style=\"height: 15px\" aria-hidden=\"true\"><\/div>\n<p>Adding imports from the Couchbase Java SDK (in the code sample below) enables the cluster connection classes for your project. We&#8217;ll add more throughout this exercise, but feel free to skip to the full code sample at the end of the post.<\/p>\n<pre>import com.couchbase.client.java.*;\r\n<\/pre>\n<div class=\"wp-block-spacer\" style=\"height: 15px\" aria-hidden=\"true\"><\/div>\n<p>Add a basic cluster connection string to <code>main()<\/code>, as you see in the example below. Connection parameters include the IP address or the name of a node in the Couchbase cluster along with the username\/password. Note that I use my main administrator login here for simplicity because it has full permissions.<\/p>\n<pre>    public static void main( String[] args )\r\n    {\r\n        System.out.println( \"Hello World!\" );\r\n        Cluster cluster = Cluster.connect(\"192.168.0.158\",\"Administrator\",\"Administrator\");\r\n    }\r\n<\/pre>\n<div class=\"wp-block-spacer\" style=\"height: 15px\" aria-hidden=\"true\"><\/div>\n<p>When you have the connection info entered, run another test build and the output should show that a node was connected:<\/p>\n<pre>INFO: [com.couchbase.node][NodeConnectedEvent] Node connected {\"coreId\":\"0x9bb7352900000001\",\"managerPort\":\"8091\",\"remote\":\"192.168.0.158\/\"}\r\n<\/pre>\n<div class=\"wp-block-spacer\" style=\"height: 15px\" aria-hidden=\"true\"><\/div>\n<h2>Get a Document<\/h2>\n<p>If you made it this far, you&#8217;re more than halfway there!<\/p>\n<p>Next, we&#8217;re going to request a specific document using its ID. Document IDs are unique names for every document in the bucket or collection of documents in a bucket.<\/p>\n<p>The travel-sample bucket that comes with <a href=\"https:\/\/www.couchbase.com\/products\/capella\/\" target=\"_blank\" rel=\"noopener\">Couchbase<\/a> includes airlines, hotels, and more \u2013 all so you can test your code on real data.<\/p>\n<p>The image below shows how you can browse available documents in a bucket using the web console.<\/p>\n<div id=\"attachment_11533\" style=\"width: 778px\" class=\"wp-caption aligncenter\"><a href=\"https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/2021\/07\/couchbase-document-viewer.png\"><img loading=\"lazy\" decoding=\"async\" aria-describedby=\"caption-attachment-11533\" class=\"size-medium_large wp-image-11533\" src=\"https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/2021\/07\/couchbase-document-viewer-768x432.png\" alt=\"Couchbase web UI showing document viewer\" width=\"768\" height=\"432\" srcset=\"https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2021\/07\/couchbase-document-viewer-768x432.png 768w, https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2021\/07\/couchbase-document-viewer-300x169.png 300w, https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2021\/07\/couchbase-document-viewer-1024x576.png 1024w, https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2021\/07\/couchbase-document-viewer-20x11.png 20w, https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2021\/07\/couchbase-document-viewer.png 1280w\" sizes=\"auto, (max-width: 768px) 100vw, 768px\" \/><\/a><p id=\"caption-attachment-11533\" class=\"wp-caption-text\">Couchbase document viewer in the web console<\/p><\/div>\n<p>To access documents in the database, we need some more classes that interact with key-value operations like getting and setting documents.<\/p>\n<p>Here&#8217;s how you add import for key-value operations:<\/p>\n<pre>import com.couchbase.client.java.kv.GetResult;\r\n<\/pre>\n<div class=\"wp-block-spacer\" style=\"height: 15px\" aria-hidden=\"true\"><\/div>\n<p>Next, you need to define a collection and bucket to connect to and provide a document ID to fetch:<\/p>\n<pre>        Bucket bucket = cluster.bucket(\"travel-sample\");\r\n        Collection collection = bucket.defaultCollection();\r\n\r\n        \/\/ Get a Document\r\n        GetResult getResult = collection.get(\"airline_10\");\r\n        System.out.println(getResult);\r\n<\/pre>\n<div class=\"wp-block-spacer\" style=\"height: 15px\" aria-hidden=\"true\"><\/div>\n<p>Scopes and collections are used to group similar types of documents for different applications. In this example, we just use the defaults that include everything.<\/p>\n<p>Be more precise if you want. For example, you can just print the name of the document:<\/p>\n<pre>String name = getResult.contentAsObject().getString(\"name\");\r\nSystem.out.println(name);\r\n<\/pre>\n<div class=\"wp-block-spacer\" style=\"height: 15px\" aria-hidden=\"true\"><\/div>\n<p>Run this code and the output will show the raw JSON of the document, plus the above string taken from the name field:<\/p>\n<pre>{\"country\":\"United States\",\"iata\":\"Q5\",\"name\":\"40-Mile Air\",\"callsign\":\"MILE-AIR\",\"icao\":\"MLA\",\"id\":10,\"type\":\"airline\"}\r\n\r\n40-Mile Air\r\n<\/pre>\n<div class=\"wp-block-spacer\" style=\"height: 15px\" aria-hidden=\"true\"><\/div>\n<p>That&#8217;s all it takes to fetch a specific document. Congratulations if you made it this far!<\/p>\n<h2>Create or Upsert a Document<\/h2>\n<p>Creating a document isn&#8217;t much harder than fetching one.<\/p>\n<p>Ensure that your user settings allow you to create new documents in the given bucket. Then we&#8217;ll add a couple imports and build a simple JSON document that we send\/insert\/update\/upsert into the database.<\/p>\n<p>While we aren&#8217;t going to do anything fancy with tracking versions of documents or related mutations, the SDK does return the status of the operation for us to use later on. Here&#8217;s how to add a couple more imports to handle the update of documents and create JSON objects:<\/p>\n<pre>import com.couchbase.client.java.kv.MutationResult;\r\nimport com.couchbase.client.java.json.*;\r\n<\/pre>\n<div class=\"wp-block-spacer\" style=\"height: 15px\" aria-hidden=\"true\"><\/div>\n<p>Then we add code for creating a basic document, including any field you want in the JSON document:<\/p>\n<pre>        MutationResult upsertResult = collection.upsert(\r\n            \"airbnb_1\",\r\n            JsonObject.create().put(\"name\", \"Tyler's AirBnB\")\r\n                .put(\"country\", \"Canada\")\r\n                .put(\"type\", \"hotel\")\r\n        );\r\n<\/pre>\n<div class=\"wp-block-spacer\" style=\"height: 15px\" aria-hidden=\"true\"><\/div>\n<p>Note that an ID is provided (<code>airbnb_1<\/code>) and then the JSON document is formed and submitted to the database (<code>upsert<\/code>) all in one command. Note that the ID itself is not part of the JSON but is a string passed to the function.<\/p>\n<p>An upsert will create a new document if none exists, or update any existing ones with the same ID.<\/p>\n<p>Now let&#8217;s change the original document fetch to get the new document we just created:<\/p>\n<pre>GetResult getResult = collection.get(\"airbnb_1\");\r\n<\/pre>\n<div class=\"wp-block-spacer\" style=\"height: 15px\" aria-hidden=\"true\"><\/div>\n<p>The terminal log should print the raw result object and then the name from our new document:<\/p>\n<pre>GetResult{content={\"name\":\"Tyler's AirBnB\",\"type\":\"hotel\",\"country\":\"Canada\"}, flags=0x2000000, cas=0x16917e1447b40000, expiry=Optional.empty}\r\nTyler's AirBnB\r\n<\/pre>\n<div class=\"wp-block-spacer\" style=\"height: 15px\" aria-hidden=\"true\"><\/div>\n<p>And that&#8217;s it!<\/p>\n<h2>Next Steps<\/h2>\n<p>This simple tutorial should get you started with the Couchbase Java SDK quickly. Future posts in this series will examine other services such as Query and Full-Text Search.<\/p>\n<p>For more information, <a href=\"https:\/\/docs.couchbase.com\/java-sdk\/current\/hello-world\/start-using-sdk.html?ref=blog\">check out the Couchbase Java SDK documentation that covers similar concepts.<\/a><\/p>\n<h3>Full Couchbase Client Code Example<\/h3>\n<pre class=\"lang:java decode:true\">package com.example;\r\n\r\nimport com.couchbase.client.java.*;\r\nimport com.couchbase.client.java.kv.GetResult;\r\nimport com.couchbase.client.java.kv.MutationResult;\r\nimport com.couchbase.client.java.json.*;\r\n\r\npublic class App \r\n{\r\n    public static void main( String[] args )\r\n    {\r\n        System.out.println( \"Hello World!\" );\r\n        Cluster cluster = Cluster.connect(\"192.168.0.158\",\"Administrator\",\"Administrator\");\r\n        Bucket bucket = cluster.bucket(\"travel-sample\");\r\n        Collection collection = bucket.defaultCollection();\r\n        \r\n        MutationResult upsertResult = collection.upsert(\r\n            \"airbnb_1\",\r\n            JsonObject.create().put(\"name\", \"Tyler's AirBnB\")\r\n                .put(\"country\", \"Canada\")\r\n                .put(\"type\", \"hotel\")\r\n        );\r\n\r\n        \/\/ Get a Document\r\n        \/\/GetResult getResult = collection.get(\"airline_10\");\r\n        GetResult getResult = collection.get(\"airbnb_1\");\r\n        System.out.println(getResult);\r\n\r\n        \/\/ Print specific field in document results\r\n        String name = getResult.contentAsObject().getString(\"name\");\r\n        System.out.println(name);\r\n    }\r\n}\r\n\r\n<\/pre>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Using Java with Couchbase doesn&#8217;t have to be hard, even for a new developer. In this quickstart tutorial, we&#8217;re going to walk through the basics of creating and fetching JSON documents in Couchbase using the Java SDK. With minimalist code [&hellip;]<\/p>\n","protected":false},"author":75185,"featured_media":11533,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"inline_featured_image":false,"footnotes":""},"categories":[1815,2242,1816,1818,2201],"tags":[1261,2313,1874,1590,9317,1764],"ppma_author":[9163],"class_list":["post-11531","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-best-practices-and-tutorials","category-connectors","category-couchbase-server","category-java","category-tools-sdks","tag-json","tag-key-value","tag-maven","tag-microsoft","tag-upsert","tag-visual-studio-code"],"acf":[],"yoast_head":"<!-- This site is optimized with the Yoast SEO Premium plugin v25.8 (Yoast SEO v25.8) - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Using Java SDK: The Basics of Get &amp; Upsert | Couchbase<\/title>\n<meta name=\"description\" content=\"This post will walk you through the basics of creating and fetching JSON documents in Couchbase using the Java SDK with minimalist code samples.\" \/>\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\/using-java-sdk-for-couchbase-basics-get-upsert\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Using the Java SDK for Couchbase: The Basics of Get &amp; Upsert\" \/>\n<meta property=\"og:description\" content=\"This post will walk you through the basics of creating and fetching JSON documents in Couchbase using the Java SDK with minimalist code samples.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.couchbase.com\/blog\/using-java-sdk-for-couchbase-basics-get-upsert\/\" \/>\n<meta property=\"og:site_name\" content=\"The Couchbase Blog\" \/>\n<meta property=\"article:published_time\" content=\"2021-07-20T10:47:56+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2024-08-30T09:55:10+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2021\/07\/couchbase-document-viewer.png\" \/>\n\t<meta property=\"og:image:width\" content=\"1280\" \/>\n\t<meta property=\"og:image:height\" content=\"720\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/png\" \/>\n<meta name=\"author\" content=\"Tyler Mitchell - Senior Product Marketing Manager\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\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=\"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\/using-java-sdk-for-couchbase-basics-get-upsert\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/www.couchbase.com\/blog\/using-java-sdk-for-couchbase-basics-get-upsert\/\"},\"author\":{\"name\":\"Tyler Mitchell - Senior Product Marketing Manager\",\"@id\":\"https:\/\/www.couchbase.com\/blog\/#\/schema\/person\/684cc0e5c60cd2e4b591db9621494ed0\"},\"headline\":\"Using the Java SDK for Couchbase: The Basics of Get &amp; Upsert\",\"datePublished\":\"2021-07-20T10:47:56+00:00\",\"dateModified\":\"2024-08-30T09:55:10+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/www.couchbase.com\/blog\/using-java-sdk-for-couchbase-basics-get-upsert\/\"},\"wordCount\":889,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\/\/www.couchbase.com\/blog\/#organization\"},\"image\":{\"@id\":\"https:\/\/www.couchbase.com\/blog\/using-java-sdk-for-couchbase-basics-get-upsert\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2021\/07\/couchbase-document-viewer.png\",\"keywords\":[\"JSON\",\"key value\",\"maven\",\"Microsoft\",\"upsert\",\"Visual Studio Code\"],\"articleSection\":[\"Best Practices and Tutorials\",\"Connectors\",\"Couchbase Server\",\"Java\",\"Tools &amp; SDKs\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\/\/www.couchbase.com\/blog\/using-java-sdk-for-couchbase-basics-get-upsert\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.couchbase.com\/blog\/using-java-sdk-for-couchbase-basics-get-upsert\/\",\"url\":\"https:\/\/www.couchbase.com\/blog\/using-java-sdk-for-couchbase-basics-get-upsert\/\",\"name\":\"Using Java SDK: The Basics of Get & Upsert | Couchbase\",\"isPartOf\":{\"@id\":\"https:\/\/www.couchbase.com\/blog\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/www.couchbase.com\/blog\/using-java-sdk-for-couchbase-basics-get-upsert\/#primaryimage\"},\"image\":{\"@id\":\"https:\/\/www.couchbase.com\/blog\/using-java-sdk-for-couchbase-basics-get-upsert\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2021\/07\/couchbase-document-viewer.png\",\"datePublished\":\"2021-07-20T10:47:56+00:00\",\"dateModified\":\"2024-08-30T09:55:10+00:00\",\"description\":\"This post will walk you through the basics of creating and fetching JSON documents in Couchbase using the Java SDK with minimalist code samples.\",\"breadcrumb\":{\"@id\":\"https:\/\/www.couchbase.com\/blog\/using-java-sdk-for-couchbase-basics-get-upsert\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.couchbase.com\/blog\/using-java-sdk-for-couchbase-basics-get-upsert\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.couchbase.com\/blog\/using-java-sdk-for-couchbase-basics-get-upsert\/#primaryimage\",\"url\":\"https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2021\/07\/couchbase-document-viewer.png\",\"contentUrl\":\"https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2021\/07\/couchbase-document-viewer.png\",\"width\":1280,\"height\":720,\"caption\":\"Couchbase document viewer in the web console\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.couchbase.com\/blog\/using-java-sdk-for-couchbase-basics-get-upsert\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/www.couchbase.com\/blog\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Using the Java SDK for Couchbase: The Basics of Get &amp; Upsert\"}]},{\"@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\/684cc0e5c60cd2e4b591db9621494ed0\",\"name\":\"Tyler Mitchell - Senior Product Marketing Manager\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@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. His personal passion is all things geospatial, having worked in GIS for half his career. Now AI and Vector Search is top of mind.\",\"sameAs\":[\"https:\/\/linkedin.com\/in\/tylermitchell\",\"https:\/\/x.com\/1tylermitchell\",\"https:\/\/www.youtube.com\/channel\/UCBZFuoiTcg0f3lGSQwLjeTg\"],\"url\":\"https:\/\/www.couchbase.com\/blog\/author\/tylermitchell\/\"}]}<\/script>\n<!-- \/ Yoast SEO Premium plugin. -->","yoast_head_json":{"title":"Using Java SDK: The Basics of Get & Upsert | Couchbase","description":"This post will walk you through the basics of creating and fetching JSON documents in Couchbase using the Java SDK with minimalist code samples.","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\/using-java-sdk-for-couchbase-basics-get-upsert\/","og_locale":"en_US","og_type":"article","og_title":"Using the Java SDK for Couchbase: The Basics of Get &amp; Upsert","og_description":"This post will walk you through the basics of creating and fetching JSON documents in Couchbase using the Java SDK with minimalist code samples.","og_url":"https:\/\/www.couchbase.com\/blog\/using-java-sdk-for-couchbase-basics-get-upsert\/","og_site_name":"The Couchbase Blog","article_published_time":"2021-07-20T10:47:56+00:00","article_modified_time":"2024-08-30T09:55:10+00:00","og_image":[{"width":1280,"height":720,"url":"https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2021\/07\/couchbase-document-viewer.png","type":"image\/png"}],"author":"Tyler Mitchell - Senior Product Marketing Manager","twitter_card":"summary_large_image","twitter_creator":"@1tylermitchell","twitter_misc":{"Written by":"Tyler Mitchell - Senior Product Marketing Manager","Est. reading time":"5 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/www.couchbase.com\/blog\/using-java-sdk-for-couchbase-basics-get-upsert\/#article","isPartOf":{"@id":"https:\/\/www.couchbase.com\/blog\/using-java-sdk-for-couchbase-basics-get-upsert\/"},"author":{"name":"Tyler Mitchell - Senior Product Marketing Manager","@id":"https:\/\/www.couchbase.com\/blog\/#\/schema\/person\/684cc0e5c60cd2e4b591db9621494ed0"},"headline":"Using the Java SDK for Couchbase: The Basics of Get &amp; Upsert","datePublished":"2021-07-20T10:47:56+00:00","dateModified":"2024-08-30T09:55:10+00:00","mainEntityOfPage":{"@id":"https:\/\/www.couchbase.com\/blog\/using-java-sdk-for-couchbase-basics-get-upsert\/"},"wordCount":889,"commentCount":0,"publisher":{"@id":"https:\/\/www.couchbase.com\/blog\/#organization"},"image":{"@id":"https:\/\/www.couchbase.com\/blog\/using-java-sdk-for-couchbase-basics-get-upsert\/#primaryimage"},"thumbnailUrl":"https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2021\/07\/couchbase-document-viewer.png","keywords":["JSON","key value","maven","Microsoft","upsert","Visual Studio Code"],"articleSection":["Best Practices and Tutorials","Connectors","Couchbase Server","Java","Tools &amp; SDKs"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/www.couchbase.com\/blog\/using-java-sdk-for-couchbase-basics-get-upsert\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/www.couchbase.com\/blog\/using-java-sdk-for-couchbase-basics-get-upsert\/","url":"https:\/\/www.couchbase.com\/blog\/using-java-sdk-for-couchbase-basics-get-upsert\/","name":"Using Java SDK: The Basics of Get & Upsert | Couchbase","isPartOf":{"@id":"https:\/\/www.couchbase.com\/blog\/#website"},"primaryImageOfPage":{"@id":"https:\/\/www.couchbase.com\/blog\/using-java-sdk-for-couchbase-basics-get-upsert\/#primaryimage"},"image":{"@id":"https:\/\/www.couchbase.com\/blog\/using-java-sdk-for-couchbase-basics-get-upsert\/#primaryimage"},"thumbnailUrl":"https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2021\/07\/couchbase-document-viewer.png","datePublished":"2021-07-20T10:47:56+00:00","dateModified":"2024-08-30T09:55:10+00:00","description":"This post will walk you through the basics of creating and fetching JSON documents in Couchbase using the Java SDK with minimalist code samples.","breadcrumb":{"@id":"https:\/\/www.couchbase.com\/blog\/using-java-sdk-for-couchbase-basics-get-upsert\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.couchbase.com\/blog\/using-java-sdk-for-couchbase-basics-get-upsert\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.couchbase.com\/blog\/using-java-sdk-for-couchbase-basics-get-upsert\/#primaryimage","url":"https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2021\/07\/couchbase-document-viewer.png","contentUrl":"https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2021\/07\/couchbase-document-viewer.png","width":1280,"height":720,"caption":"Couchbase document viewer in the web console"},{"@type":"BreadcrumbList","@id":"https:\/\/www.couchbase.com\/blog\/using-java-sdk-for-couchbase-basics-get-upsert\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.couchbase.com\/blog\/"},{"@type":"ListItem","position":2,"name":"Using the Java SDK for Couchbase: The Basics of Get &amp; Upsert"}]},{"@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\/684cc0e5c60cd2e4b591db9621494ed0","name":"Tyler Mitchell - Senior Product Marketing Manager","image":{"@type":"ImageObject","inLanguage":"en-US","@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. His personal passion is all things geospatial, having worked in GIS for half his career. Now AI and Vector Search is top of mind.","sameAs":["https:\/\/linkedin.com\/in\/tylermitchell","https:\/\/x.com\/1tylermitchell","https:\/\/www.youtube.com\/channel\/UCBZFuoiTcg0f3lGSQwLjeTg"],"url":"https:\/\/www.couchbase.com\/blog\/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":"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. His personal passion is all things geospatial, having worked in GIS for half his career. Now AI and Vector Search is top of mind."}],"_links":{"self":[{"href":"https:\/\/www.couchbase.com\/blog\/wp-json\/wp\/v2\/posts\/11531","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\/75185"}],"replies":[{"embeddable":true,"href":"https:\/\/www.couchbase.com\/blog\/wp-json\/wp\/v2\/comments?post=11531"}],"version-history":[{"count":0,"href":"https:\/\/www.couchbase.com\/blog\/wp-json\/wp\/v2\/posts\/11531\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.couchbase.com\/blog\/wp-json\/wp\/v2\/media\/11533"}],"wp:attachment":[{"href":"https:\/\/www.couchbase.com\/blog\/wp-json\/wp\/v2\/media?parent=11531"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.couchbase.com\/blog\/wp-json\/wp\/v2\/categories?post=11531"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.couchbase.com\/blog\/wp-json\/wp\/v2\/tags?post=11531"},{"taxonomy":"author","embeddable":true,"href":"https:\/\/www.couchbase.com\/blog\/wp-json\/wp\/v2\/ppma_author?post=11531"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}