{"id":7770,"date":"2020-07-30T22:04:49","date_gmt":"2020-07-31T05:04:49","guid":{"rendered":"https:\/\/www.couchbase.com\/blog\/?p=7770"},"modified":"2025-06-13T21:01:56","modified_gmt":"2025-06-14T04:01:56","slug":"migrating-from-mongodb-to-couchbase-part-2","status":"publish","type":"post","link":"https:\/\/www.couchbase.com\/blog\/migrating-from-mongodb-to-couchbase-part-2\/","title":{"rendered":"Migrating Data from MongoDB to Couchbase, Part 2"},"content":{"rendered":"<h2>Prolog<\/h2>\n<p>The <a href=\"https:\/\/www.couchbase.com\/blog\/migrating-data-from-mongodb-to-couchbase\/\">previous article<\/a> provided details on how to migrate a MongoDB data set to Couchbase Server. This article shows you how to use the Couchbase SDK to access the data via a Java console application. Code snippets show how to connect to the Couchbase cluster, perform key\/value operations, and execute secondary lookups via N1QL queries side-by-side with corresponding code to do the same with the Mongo Java SDK.<\/p>\n<p>All code from this blog is available in the following Git repository: <a href=\"https:\/\/github.com\/dugbonsai\/mongodb-to-couchbase\">mongodb-to-couchbase<\/a>.<\/p>\n<h2>Prerequisites<\/h2>\n<p>A Couchbase cluster containing the data set as per the details in the <a href=\"https:\/\/www.couchbase.com\/blog\/migrating-data-from-mongodb-to-couchbase\/\">previous article<\/a>.<\/p>\n<h2>Create an Application User<\/h2>\n<p>Before a client (application) can connect to the Couchbase Server cluster you need to define an application user that is used for authentication by the client. Couchbase <a href=\"https:\/\/docs.couchbase.com\/server\/current\/manage\/manage-security\/manage-users-and-roles.html\">Role-Based Access Control<\/a> allows you to define users and assign appropriate roles to them. Use the web console to create an application user named <strong>mflix_client<\/strong> as follows.<\/p>\n<p>Go to the <strong>Security<\/strong> section in the web console and click <strong>ADD USER<\/strong>:<\/p>\n<p style=\"text-align: center\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-9008\" src=\"https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/2019\/10\/01.-Security-no-users.png\" alt=\"\" width=\"1443\" height=\"586\" srcset=\"https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2019\/10\/01.-Security-no-users.png 1443w, https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2019\/10\/01.-Security-no-users-300x122.png 300w, https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2019\/10\/01.-Security-no-users-1024x416.png 1024w, https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2019\/10\/01.-Security-no-users-768x312.png 768w, https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2019\/10\/01.-Security-no-users-20x8.png 20w, https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2019\/10\/01.-Security-no-users-1320x536.png 1320w\" sizes=\"auto, (max-width: 1443px) 100vw, 1443px\" \/><\/p>\n<p>Configure the <strong>mflix_client<\/strong> user as follows and click <strong>Add User<\/strong>:<\/p>\n<ol>\n<li><strong>Username<\/strong>: mflix_client<\/li>\n<li><strong>Password<\/strong>: password (or any password of your choosing).<\/li>\n<li><strong>Verify Password<\/strong>: same as <strong>Password<\/strong> value above.<\/li>\n<li><strong>Roles<\/strong>: Expand the <strong>sample_mflix<\/strong> section and select <strong>Application Access<\/strong>. Users with the <a href=\"https:\/\/docs.couchbase.com\/server\/6.5\/learn\/security\/roles.html#application-access\">Application Access role<\/a> have full read and write access to all data in the sample_mflix bucket. The role does not allow access to the Couchbase Web Console: it is intended for applications, rather than users.<\/li>\n<\/ol>\n<p style=\"text-align: center\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-9009\" src=\"https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/2019\/10\/02.-mflix_client-user.png\" alt=\"\" width=\"639\" height=\"552\" srcset=\"https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2019\/10\/02.-mflix_client-user.png 639w, https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2019\/10\/02.-mflix_client-user-300x259.png 300w, https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2019\/10\/02.-mflix_client-user-20x17.png 20w\" sizes=\"auto, (max-width: 639px) 100vw, 639px\" \/><\/p>\n<p>In the <strong>Security<\/strong> section you will see the new mflix_client user:<\/p>\n<p style=\"text-align: center\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-9010\" src=\"https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/2019\/10\/03.-Security-1-user.png\" alt=\"\" width=\"1444\" height=\"586\" srcset=\"https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2019\/10\/03.-Security-1-user.png 1444w, https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2019\/10\/03.-Security-1-user-300x122.png 300w, https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2019\/10\/03.-Security-1-user-1024x416.png 1024w, https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2019\/10\/03.-Security-1-user-768x312.png 768w, https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2019\/10\/03.-Security-1-user-20x8.png 20w, https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2019\/10\/03.-Security-1-user-1320x536.png 1320w\" sizes=\"auto, (max-width: 1444px) 100vw, 1444px\" \/><\/p>\n<h2>Create Indexes for N1QL Queries<\/h2>\n<p><a href=\"https:\/\/docs.couchbase.com\/server\/current\/learn\/services-and-indexes\/indexes\/indexes.html\">Secondary Indexes<\/a> in Couchbase Server support the efficient execution of queries (or secondary lookups) just like indexes in MongoDB. Code samples in this article execute <a href=\"https:\/\/docs.couchbase.com\/server\/current\/n1ql\/n1ql-language-reference\/index.html\">N1QL queries<\/a> that use two indexes you will create by executing N1QL queries. Go to the <strong>Query<\/strong> section in the web console:<\/p>\n<p style=\"text-align: center\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-9011\" src=\"https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/2019\/10\/04.-Query-workbench.png\" alt=\"\" width=\"1438\" height=\"586\" srcset=\"https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2019\/10\/04.-Query-workbench.png 1438w, https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2019\/10\/04.-Query-workbench-300x122.png 300w, https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2019\/10\/04.-Query-workbench-1024x417.png 1024w, https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2019\/10\/04.-Query-workbench-768x313.png 768w, https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2019\/10\/04.-Query-workbench-20x8.png 20w, https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2019\/10\/04.-Query-workbench-1320x538.png 1320w\" sizes=\"auto, (max-width: 1438px) 100vw, 1438px\" \/><\/p>\n<p>The first index is on the name attribute of all comment documents in the sample_mflix bucket. Enter the following N1QL statement in the <strong>Query Editor:<\/strong><\/p>\n<pre class=\"lang:default decode:true\">CREATE INDEX idx1 on sample_mflix(name) WHERE type=\"comment\"<\/pre>\n<p style=\"text-align: center\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-9012\" src=\"https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/2019\/10\/05.-Create-index-idx1-statement.png\" alt=\"\" width=\"1444\" height=\"585\" srcset=\"https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2019\/10\/05.-Create-index-idx1-statement.png 1444w, https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2019\/10\/05.-Create-index-idx1-statement-300x122.png 300w, https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2019\/10\/05.-Create-index-idx1-statement-1024x415.png 1024w, https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2019\/10\/05.-Create-index-idx1-statement-768x311.png 768w, https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2019\/10\/05.-Create-index-idx1-statement-20x8.png 20w, https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2019\/10\/05.-Create-index-idx1-statement-1320x535.png 1320w\" sizes=\"auto, (max-width: 1444px) 100vw, 1444px\" \/><\/p>\n<p>Click <strong>Execute<\/strong> and after a few moments the <a href=\"https:\/\/docs.couchbase.com\/server\/current\/n1ql\/n1ql-language-reference\/createindex.html\">index creation<\/a> is complete:<\/p>\n<p style=\"text-align: center\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-9013\" src=\"https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/2019\/10\/06.-Create-index-idx1-complete.png\" alt=\"\" width=\"1444\" height=\"586\" srcset=\"https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2019\/10\/06.-Create-index-idx1-complete.png 1444w, https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2019\/10\/06.-Create-index-idx1-complete-300x122.png 300w, https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2019\/10\/06.-Create-index-idx1-complete-1024x416.png 1024w, https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2019\/10\/06.-Create-index-idx1-complete-768x312.png 768w, https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2019\/10\/06.-Create-index-idx1-complete-20x8.png 20w, https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2019\/10\/06.-Create-index-idx1-complete-1320x536.png 1320w\" sizes=\"auto, (max-width: 1444px) 100vw, 1444px\" \/><\/p>\n<p>The second index is on the year, imdb.rating, &amp; title attributes of all movie documents in the sample_mflix bucket. Enter the following N1QL statement in the <strong>Query Editor<\/strong>:<\/p>\n<pre class=\"lang:default decode:true\">CREATE INDEX idx2 on sample_mflix(year, imdb.rating, title) WHERE type=\"movie\"<\/pre>\n<p style=\"text-align: center\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-9014\" src=\"https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/2019\/10\/07.-Create-index-idx2-statement.png\" alt=\"\" width=\"1444\" height=\"586\" srcset=\"https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2019\/10\/07.-Create-index-idx2-statement.png 1444w, https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2019\/10\/07.-Create-index-idx2-statement-300x122.png 300w, https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2019\/10\/07.-Create-index-idx2-statement-1024x416.png 1024w, https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2019\/10\/07.-Create-index-idx2-statement-768x312.png 768w, https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2019\/10\/07.-Create-index-idx2-statement-20x8.png 20w, https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2019\/10\/07.-Create-index-idx2-statement-1320x536.png 1320w\" sizes=\"auto, (max-width: 1444px) 100vw, 1444px\" \/><\/p>\n<p>Click <strong>Execute<\/strong> and after a few moments the index creation is complete:<\/p>\n<p style=\"text-align: center\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-9015\" src=\"https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/2019\/10\/08.-Create-index-idx2-complete.png\" alt=\"\" width=\"1444\" height=\"586\" srcset=\"https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2019\/10\/08.-Create-index-idx2-complete.png 1444w, https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2019\/10\/08.-Create-index-idx2-complete-300x122.png 300w, https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2019\/10\/08.-Create-index-idx2-complete-1024x416.png 1024w, https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2019\/10\/08.-Create-index-idx2-complete-768x312.png 768w, https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2019\/10\/08.-Create-index-idx2-complete-20x8.png 20w, https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2019\/10\/08.-Create-index-idx2-complete-1320x536.png 1320w\" sizes=\"auto, (max-width: 1444px) 100vw, 1444px\" \/><\/p>\n<p>Go to the <strong>Indexes<\/strong> section in the web console to verify that indexes <strong>idx1<\/strong> &amp; <strong>idx2<\/strong> exist:<\/p>\n<p style=\"text-align: center\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-9016\" src=\"https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/2019\/10\/09.-Index-list-2-indexes.png\" alt=\"\" width=\"1443\" height=\"586\" srcset=\"https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2019\/10\/09.-Index-list-2-indexes.png 1443w, https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2019\/10\/09.-Index-list-2-indexes-300x122.png 300w, https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2019\/10\/09.-Index-list-2-indexes-1024x416.png 1024w, https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2019\/10\/09.-Index-list-2-indexes-768x312.png 768w, https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2019\/10\/09.-Index-list-2-indexes-20x8.png 20w, https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2019\/10\/09.-Index-list-2-indexes-1320x536.png 1320w\" sizes=\"auto, (max-width: 1443px) 100vw, 1443px\" \/><\/p>\n<h2>Convert MongoDB API calls to Couchbase API calls<\/h2>\n<p>The sample code for this article uses the Couchbase &amp; MongoDB Java SDKs and is provided only as an example of how to use some of the SDK APIs. Refer to the following links for the full Couchbase SDK documentation for your language:<\/p>\n<ul>\n<li><a href=\"https:\/\/docs.couchbase.com\/c-sdk\/current\/hello-world\/start-using-sdk.html\">C<\/a><\/li>\n<li><a href=\"https:\/\/docs.couchbase.com\/dotnet-sdk\/current\/hello-world\/start-using-sdk.html\">.NET<\/a><\/li>\n<li><a href=\"https:\/\/docs.couchbase.com\/go-sdk\/current\/hello-world\/start-using-sdk.html\">Go<\/a><\/li>\n<li><a href=\"https:\/\/docs.couchbase.com\/java-sdk\/current\/hello-world\/start-using-sdk.html\">Java<\/a><\/li>\n<li><a href=\"https:\/\/docs.couchbase.com\/nodejs-sdk\/current\/hello-world\/start-using-sdk.html\">Node.js<\/a><\/li>\n<li><a href=\"https:\/\/docs.couchbase.com\/php-sdk\/current\/hello-world\/start-using-sdk.html\">PHP<\/a><\/li>\n<li><a href=\"https:\/\/docs.couchbase.com\/python-sdk\/current\/hello-world\/start-using-sdk.html\">Python<\/a><\/li>\n<li><a href=\"https:\/\/docs.couchbase.com\/scala-sdk\/1.0\/hello-world\/start-using-sdk.html\">Scala<\/a><\/li>\n<\/ul>\n<h3>Connect to Couchbase Server<\/h3>\n<p>In order to access cluster resources, clients must <a href=\"https:\/\/docs.couchbase.com\/java-sdk\/current\/sdk-authentication-overview.html\">authenticate<\/a> by passing appropriate credentials to Couchbase Server. The sample code uses the mflix_client application user credentials created above to authenticate.<\/p>\n<p>The following code sample connects to the Couchbase cluster running on the specified node, gets a reference to the mflix_client bucket, and a reference to the default collection in that bucket.<\/p>\n<p><u>Couchbase<\/u><\/p>\n<pre class=\"lang:java decode:true\">Cluster cluster = Cluster.connect(\"127.0.0.1\", \"mflix_client\", \"password\");\r\nBucket bucket = cluster.bucket(\"sample_mflix\");\r\nCollection collection = bucket.defaultCollection();<\/pre>\n<p><u>MongoDB<\/u><\/p>\n<pre class=\"lang:java decode:true\">MongoClient mongoClient = MongoClients.create(\"mongodb+srv:\/\/&lt;user&gt;:&lt;password&gt;@&lt;host&gt;\/&lt;database&gt; \");\r\nMongoDatabase mongoDatabase = mongoClient.getDatabase(\"sample_mflix\");\r\nMongoCollection&lt;Document&gt; comments = mongoDatabase.getCollection(\"comments\");\r\nMongoCollection&lt;Document&gt; movies = mongoDatabase.getCollection(\"movies\");<\/pre>\n<h3>Retrieve a Document by ID<\/h3>\n<p>Use the <strong>Collection.get()<\/strong> method to <a href=\"https:\/\/docs.couchbase.com\/java-sdk\/3.0\/howtos\/kv-operations.html#retrieving-documents\">retrieve full documents<\/a> by ID. The following code sample retrieves two documents from the sample_mflix bucket default collection.<\/p>\n<p><u>Couchbase<\/u><\/p>\n<pre class=\"lang:java decode:true\">\/\/ get() will throw an exception if a document with the specified ID does not exist\r\nGetResult comment = collection.get(\"comment:5a9427648b0beebeb69579cc\");\r\nSystem.out.println(comment.contentAsObject());\r\n\r\nGetResult movie = collection.get(\"movie:573a1390f29313caabcd4135\");\r\nSystem.out.println(movie.contentAsObject());<\/pre>\n<p><u>MongoDB<\/u><\/p>\n<pre class=\"lang:java decode:true\">comments.find(Filters.eq(\"_id\", new ObjectId(\"5a9427648b0beebeb69579cc\")));\r\nmovies.find(Filters.eq(\"_id\", new ObjectId(\"573a1390f29313caabcd4135\")));<\/pre>\n<h3>Insert a New Document<\/h3>\n<p>Use the <strong>Collection.insert()<\/strong> method to <a href=\"https:\/\/docs.couchbase.com\/java-sdk\/3.0\/howtos\/kv-operations.html#insert\">create a new document<\/a> with the specified ID &amp; content if it does not already exist. The following code sample inserts this document in the sample_mflix bucket default collection:<\/p>\n<pre class=\"lang:java decode:true\">{\r\n  \"name\":\"Anat Chase\",\r\n  \"email\":\"anat_chase@fakegmail.com\",\r\n  \"movie_id\":\"movie:573a1390f29313caabcd4135\",\r\n  \"text\":\"This is Anat's review\",\r\n  \"type\":\"comment\"\r\n}<\/pre>\n<p><u>Couchbase<\/u><\/p>\n<pre class=\"lang:java decode:true\">JsonObject doc = JsonObject.create()\r\n  .put(\"name\", \"Anat Chase\")\r\n  .put(\"email\", \"anat_chase@fakegmail.com\")\r\n  .put(\"movie_id\", \"movie:573a1390f29313caabcd4135\")\r\n  .put(\"text\", \"This is Anat's review\")\r\n  .put(\"type\", \"comment\");\r\n\r\n\/\/ insert() will throw an exception if a document with the specified ID already exists\r\ncollection.insert(\"comment:5a9427648b0beebeb69579c0\", doc);<\/pre>\n<p><u>MongoDB<\/u><\/p>\n<pre class=\"lang:java decode:true\">Document doc = new Document(\"_id\", new ObjectId(\"5a9427648b0beebeb69579c0\"))\r\n  .append(\"name\", \"Anat Chase\")\r\n  .append(\"email\", \"anat_chase@fakegmail.com\")\r\n  .append(\"movie_id\", new ObjectId(\"573a1390f29313caabcd4135\"))\r\n  .append(\"text\", \"This is Anat's review\");\r\n\r\ncomments.insertOne(doc);<\/pre>\n<h3>Insert Multiple New Documents<\/h3>\n<p><a href=\"https:\/\/docs.couchbase.com\/java-sdk\/3.0\/howtos\/concurrent-async-apis.html#batching\">Batching operations<\/a> allows you to make better utilization of your network and speed up your application by increasing network throughput and reducing latency. Batched operations work by\u00a0<em>pipelining<\/em>\u00a0requests over the network. When requests are pipelined, they are sent in one large group to the cluster. The cluster in turn\u00a0<em>pipelines<\/em>\u00a0responses back to the client.<\/p>\n<p>The following code sample uses this approach to insert two new documents into the sample_mflix bucket.<\/p>\n<p><u>Couchbase<\/u><\/p>\n<pre class=\"lang:java decode:true\">\/\/ Create two JSON documents\r\nList&lt;Tuple2&lt;String, JsonObject&gt;&gt; documents = new ArrayList&lt;Tuple2&lt;String, JsonObject&gt;&gt;();\r\ndoc = JsonObject.create()\r\n  .put(\"name\", \"Anat Chase\")\r\n  .put(\"email\", \"anat_chase@fakegmail.com\")\r\n  .put(\"movie_id\", \"movie:573a1390f29313caabcd42e8\")\r\n  .put(\"text\", \"This is Anat's review\")\r\n  .put(\"type\", \"comment\");\r\ndocuments.add(Tuples.of(\"comment:5a9427648b0beebeb69579c1\", doc));\r\n\r\nJsonObject doc2 = JsonObject.create()\r\n  .put(\"name\", \"Anat Chase\")\r\n  .put(\"email\", \"anat_chase@fakegmail.com\")\r\n  .put(\"movie_id\", \"movie:573a1390f29313caabcd4323\")\r\n  .put(\"text\", \"This is Anat's review\")\r\n  .put(\"type\", \"comment\");\r\ndocuments.add(Tuples.of(\"comment:5a9427648b0beebeb69579c2\", doc2));\r\n\r\n\/\/ Insert the 2 documents in one batch, waiting until the last one is done.\r\n\/\/ insert() will throw an exception if a document with the specified ID already exists\r\nFlux\r\n  .fromIterable(documents)\r\n    .parallel().runOn(Schedulers.elastic())\r\n    .concatMap(doc3 -&gt; reactiveCollection.insert(doc3.getT1(), doc3.getT2())\r\n      .onErrorResume(e -&gt; Mono.error(new Exception(doc3.getT1(), e))))\r\n    .sequential().collectList().block();<\/pre>\n<p><u>MongoDB<\/u><\/p>\n<pre class=\"lang:java decode:true\">List&lt;Document&gt; documents = new ArrayList&lt;Document&gt;();\r\nDocument doc1 = new Document(\"_id\", new ObjectId(\"5a9427648b0beebeb69579c1\"))\r\n  .append(\"name\", \"Anat Chase\")\r\n  .append(\"email\", \"anat_chase@fakegmail.com\")\r\n  .append(\"movie_id\", new ObjectId(\"573a1390f29313caabcd42e8\"))\r\n  .append(\"text\", \"This is Anat's review\");\r\ndocuments.add(doc1); \r\n\r\nDocument doc2 = new Document(\"_id\", new ObjectId(\"5a9427648b0beebeb69579c2\"))\r\n  .append(\"name\", \"Anat Chase\")\r\n  .append(\"email\", \"anat_chase@fakegmail.com\")\r\n  .append(\"movie_id\", new ObjectId(\"573a1390f29313caabcd4323\"))\r\n  .append(\"text\", \"This is Anat's review\");\r\ndocuments.add(doc2);\r\n\r\ncomments.insertMany(documents);<\/pre>\n<h3>Update an Existing Document<\/h3>\n<p>Use the <strong>Collection.replace()<\/strong> method to <a href=\"https:\/\/docs.couchbase.com\/java-sdk\/3.0\/howtos\/kv-operations.html#replace\">update an existing document<\/a> with the specified ID only if it already exists. Couchbase supports <a href=\"https:\/\/docs.couchbase.com\/java-sdk\/3.0\/howtos\/subdocument-operations.html\">sub-document operations<\/a> which can be used to efficiently access\u00a0<em>parts<\/em>\u00a0of documents. Sub-document operations may be quicker and more network-efficient than\u00a0<em>full-document\u00a0<\/em>operations because they only transmit the accessed sections of the document over the network. Full-document and sub-document operations are atomic, allowing safe modifications to documents with built-in concurrency control.<\/p>\n<p>The following code sample uses sub-document operations to update the text attribute of a specified document.<\/p>\n<p><u>Couchbase<\/u><\/p>\n<pre class=\"lang:java decode:true\">\/\/ Update a document using the sub-document API to modify the specific attribute(s)\r\n\/\/ replace() will throw an exception if a document with the specified ID does not exist\r\ncollection.mutateIn(\r\n  \"comment:5a9427648b0beebeb69579c0\",\r\n  Arrays.asList(replace(\"text\", \"This is not Anat's review\")));<\/pre>\n<p><u>MongoDB<\/u><\/p>\n<pre class=\"lang:java decode:true\">comments.updateOne(\r\n  Filters.eq(\"_id\", new ObjectId(\"5a9427648b0beebeb69579c0\")),\r\n  Updates.combine(Updates.set(\"text\", \"\")));<\/pre>\n<h3>Update Multiple Documents<\/h3>\n<p>In addition to primary access via key\/value APIs, you can also <a href=\"https:\/\/docs.couchbase.com\/java-sdk\/3.0\/howtos\/n1ql-queries-with-sdk.html\">execute N1QL queries<\/a> via N1QL APIs. <a href=\"https:\/\/docs.couchbase.com\/server\/current\/n1ql\/n1ql-language-reference\/index.html\">N1QL<\/a> is a declarative language for querying, transforming, and manipulating JSON data \u2013 think SQL for JSON.<\/p>\n<p>The following code sample executes a N1QL query to update the name and email attributes for all comment documents where name is Anat Chase. This query uses the <strong>idx1<\/strong> index created above.<\/p>\n<p><u>Couchbase<\/u><\/p>\n<pre class=\"lang:java decode:true\">\/\/ execute a N1QL UPDATE query via the query API\r\nString statement =\r\n  \"UPDATE sample_mflix \" +\r\n  \"SET name='Anita Chase', email='anita_chase@fakegmail.com' \" +\r\n  \"WHERE type='comment' AND name='Anat Chase'\";\r\nQueryResult updateResult = cluster.query(statement);\r\n<\/pre>\n<p><u>MongoDB<\/u><\/p>\n<pre class=\"lang:java decode:true\">comments.updateMany(\r\n  Filters.eq(\"name\", \"Anat Chase\"),\r\n  Updates.combine(\r\n    Updates.set(\"name\", \"Anita Chase\"),\r\n    Updates.set(\"email\", \"anita_chase@fakegmail.com\")));<\/pre>\n<h3>Update or Insert a Document<\/h3>\n<p>Use the <strong>Collection.upsert()<\/strong> method to <a href=\"https:\/\/docs.couchbase.com\/java-sdk\/3.0\/howtos\/kv-operations.html#upsert\">insert the document if it does not exist, or replace it if it does<\/a>. If a document with the specified ID does not exist, upsert() will create a new document. If a document with the specified ID exists, upsert() will update the existing document. The following code sample updates an existing document in the sample_mflix bucket.<\/p>\n<p><u>Couchbase<\/u><\/p>\n<pre class=\"lang:java decode:true\">doc = JsonObject.create()\r\n  .put(\"name\", \"Mia Hannas\")\r\n  .put(\"email\", \"mia_hannas@fakegmail.com\")\r\n  .put(\"movie_id\", \"movie:573a1390f29313caabcd4135\")\r\n  .put(\"text\", \"This is Mia's review\")\r\n  .put(\"type\", \"comment\");\r\n\r\n\/\/ upsert() will update the document if it exists or insert the document if it does not exist\r\ncollection.upsert(\"comment:5a9427648b0beebeb69579c0\", doc);<\/pre>\n<p><u>MongoDB<\/u><\/p>\n<pre class=\"lang:java decode:true\">collection.replaceOne(\r\n  Filters.eq(\"_id\", new ObjectId(\"5a9427648b0beebeb69579c0\")),\r\n  new Document(\"name\", \"Mia Hannas\")\r\n    .append(\"email\", \"mia_hannas@fakegmail.com\")\r\n    .append(\"movie_id\", new ObjectId(\"573a1390f29313caabcd4135\"))\r\n    .append(\"text\", \"This is Mia's review\"),\r\n  new UpdateOptions().upsert(true));<\/pre>\n<h3>Delete a Document<\/h3>\n<p>Use the <strong>Collection.remove()<\/strong> method to <a href=\"https:\/\/docs.couchbase.com\/java-sdk\/3.0\/howtos\/kv-operations.html#removing\">remove a full document<\/a> with the specified ID. The following code sample deletes an existing document from the sample_mflix bucket.<\/p>\n<p><u>Couchbase<\/u><\/p>\n<pre class=\"lang:java decode:true\">\/\/ remove() will throw an exception if the document does not exist\r\ncollection.remove(\"comment:5a9427648b0beebeb69579c0\");<\/pre>\n<p><u>MongoDB<\/u><\/p>\n<pre class=\"lang:java decode:true\">collection.deleteOne(Filters.eq(\"_id\", new ObjectId(\"5a9427648b0beebeb69579c0\")));<\/pre>\n<h3>Delete Multiple Documents<\/h3>\n<p>You can also use N1QL queries to delete documents. The following code sample executes a N1QL query to delete multiple documents from the sample_mflix bucket. All comment documents where the name is Anita Chase will be deleted. This query uses the <strong>idx1<\/strong> index created above.<\/p>\n<p><u>Couchbase<\/u><\/p>\n<pre class=\"lang:java decode:true\">\/\/ execute a N1QL DELETE query via the query API\r\nString statement = \"DELETE FROM sample_mflix \" +\r\n  \"WHERE type='comment' AND name='Anita Chase'\";\r\n\r\nQueryResult deleteResult = cluster.query(statement);<\/pre>\n<p><u>MongoDB<\/u><\/p>\n<pre class=\"lang:java decode:true\">comments.deleteMany(Filters.eq(\"name\", \"Anita Chase\"));<\/pre>\n<h3>Data Access with N1QL<\/h3>\n<p>N1QL can also be used to perform more complicated secondary lookups of data. The following code sample executes a blocking N1QL query to select the title, year, and imdb.rating from all movie documents where the year is between 1970 and 1979, ordered by the imdb.rating. The query uses the <strong>idx2<\/strong> index created above.<\/p>\n<p>Similar to <a href=\"https:\/\/docs.couchbase.com\/java-sdk\/3.0\/howtos\/concurrent-async-apis.html#batching\">batching reactive key\/value operations<\/a>, <a href=\"https:\/\/docs.couchbase.com\/java-sdk\/3.0\/howtos\/n1ql-queries-with-sdk.html#reactive-and-async-apis\">reactive and async querying<\/a> should be used for better performance.<\/p>\n<p><u>Couchbase<\/u><\/p>\n<pre class=\"lang:default decode:true \">\/\/ execute a N1QL SELECT query (blocking) via the query API\r\nString selectStatement = \"SELECT title, year, imdb.rating FROM sample_mflix \" +\r\n  \"WHERE type='movie' AND year BETWEEN 1970 AND 1979 ORDER BY imdb.rating DESC\";\r\n\r\nfinal QueryResult selectResult = cluster.query(selectStatement);\r\nfor (JsonObject row : selectResult.rowsAsObject()) {\r\n  System.out.println(row.toString());\r\n}\r\n<\/pre>\n<p><u>MongoDB<\/u><\/p>\n<pre class=\"lang:java decode:true\">movies.find(Filters.and(Filters.gte(\"year\", 1970), Filters.lte(\"year\", 1979)))\r\n  .sort(Sorts.descending(\"imdb.rating\"))\r\n  .projection(Projections.fields(\r\n    Projections.include(\"title\", \"year\", \"imdb.rating\"),\r\n    Projections.excludeId()));<\/pre>\n<h2><strong>What&#8217;s Next<\/strong><\/h2>\n<p>Explore the other capabilities of the Couchbase SDK including <a href=\"https:\/\/docs.couchbase.com\/java-sdk\/3.0\/howtos\/analytics-using-sdk.html\">Analytics<\/a> and <a href=\"https:\/\/docs.couchbase.com\/java-sdk\/3.0\/howtos\/full-text-searching-with-sdk.html\">Full Text Search<\/a>.\u00a0Take advantage of our free, online training available at <a href=\"https:\/\/learn.couchbase.com\/\">https:\/\/learn.couchbase.com<\/a> to learn more about Couchbase.<\/p>\n<p>For detailed information on the architectural advantages of the Couchbase Data Platform over MongoDB see this document: <a href=\"https:\/\/drive.google.com\/file\/d\/14YQuCAGSsvNcnlBJkM6QnnLNzo3GadTk\/view\">Couchbase: Better Than MongoDB In Every Way<\/a>.<\/p>\n<p>Learn why other enterprises choose Couchbase over MongoDB:<\/p>\n<ul>\n<li><a href=\"https:\/\/www.couchbase.com\/customers\/directv\/\">DIRECTV<\/a><\/li>\n<li><a href=\"https:\/\/www.couchbase.com\/customers\/viber\/\">Viber<\/a><\/li>\n<li><a href=\"https:\/\/www.couchbase.com\/customers\/nuance\/\">Nuance<\/a><\/li>\n<li><a href=\"https:\/\/www.youtube.com\/watch?list=PLcspbWiU9RuunKnZwfE757B6-xsaiJV84&amp;time_continue=2&amp;v=UD_4zuga1kk\">Staples<\/a><\/li>\n<\/ul>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Prolog The previous article provided details on how to migrate a MongoDB data set to Couchbase Server. This article shows you how to use the Couchbase SDK to access the data via a Java console application. Code snippets show how [&hellip;]<\/p>\n","protected":false},"author":1352,"featured_media":7289,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"inline_featured_image":false,"footnotes":""},"categories":[1815,1816,1818,1812,2201],"tags":[2378,1393,1505,1309],"ppma_author":[9091],"class_list":["post-7770","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-best-practices-and-tutorials","category-couchbase-server","category-java","category-n1ql-query","category-tools-sdks","tag-6-5","tag-api","tag-index","tag-mongodb"],"acf":[],"yoast_head":"<!-- This site is optimized with the Yoast SEO Premium plugin v25.9 (Yoast SEO v25.9) - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Migrating Data from MongoDB to Couchbase, Part 2 - 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\/migrating-from-mongodb-to-couchbase-part-2\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Migrating Data from MongoDB to Couchbase, Part 2\" \/>\n<meta property=\"og:description\" content=\"Prolog The previous article provided details on how to migrate a MongoDB data set to Couchbase Server. This article shows you how to use the Couchbase SDK to access the data via a Java console application. Code snippets show how [&hellip;]\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.couchbase.com\/blog\/migrating-from-mongodb-to-couchbase-part-2\/\" \/>\n<meta property=\"og:site_name\" content=\"The Couchbase Blog\" \/>\n<meta property=\"article:published_time\" content=\"2020-07-31T05:04:49+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2025-06-14T04:01:56+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2019\/07\/mongo-to-couchbase.png\" \/>\n\t<meta property=\"og:image:width\" content=\"1100\" \/>\n\t<meta property=\"og:image:height\" content=\"389\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/png\" \/>\n<meta name=\"author\" content=\"Douglas Bonser, Principal Solution Engineer, Couchbase\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Douglas Bonser, Principal Solution Engineer, Couchbase\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"7 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/www.couchbase.com\/blog\/migrating-from-mongodb-to-couchbase-part-2\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/www.couchbase.com\/blog\/migrating-from-mongodb-to-couchbase-part-2\/\"},\"author\":{\"name\":\"Douglas Bonser, Principal Solution Engineer, Couchbase\",\"@id\":\"https:\/\/www.couchbase.com\/blog\/#\/schema\/person\/7fdd6feab8e25100caf61bb7836ee0ff\"},\"headline\":\"Migrating Data from MongoDB to Couchbase, Part 2\",\"datePublished\":\"2020-07-31T05:04:49+00:00\",\"dateModified\":\"2025-06-14T04:01:56+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/www.couchbase.com\/blog\/migrating-from-mongodb-to-couchbase-part-2\/\"},\"wordCount\":1179,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\/\/www.couchbase.com\/blog\/#organization\"},\"image\":{\"@id\":\"https:\/\/www.couchbase.com\/blog\/migrating-from-mongodb-to-couchbase-part-2\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2019\/07\/mongo-to-couchbase.png\",\"keywords\":[\"6.5\",\"API\",\"Index\",\"mongodb\"],\"articleSection\":[\"Best Practices and Tutorials\",\"Couchbase Server\",\"Java\",\"SQL++ \/ N1QL Query\",\"Tools &amp; SDKs\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\/\/www.couchbase.com\/blog\/migrating-from-mongodb-to-couchbase-part-2\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.couchbase.com\/blog\/migrating-from-mongodb-to-couchbase-part-2\/\",\"url\":\"https:\/\/www.couchbase.com\/blog\/migrating-from-mongodb-to-couchbase-part-2\/\",\"name\":\"Migrating Data from MongoDB to Couchbase, Part 2 - The Couchbase Blog\",\"isPartOf\":{\"@id\":\"https:\/\/www.couchbase.com\/blog\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/www.couchbase.com\/blog\/migrating-from-mongodb-to-couchbase-part-2\/#primaryimage\"},\"image\":{\"@id\":\"https:\/\/www.couchbase.com\/blog\/migrating-from-mongodb-to-couchbase-part-2\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2019\/07\/mongo-to-couchbase.png\",\"datePublished\":\"2020-07-31T05:04:49+00:00\",\"dateModified\":\"2025-06-14T04:01:56+00:00\",\"breadcrumb\":{\"@id\":\"https:\/\/www.couchbase.com\/blog\/migrating-from-mongodb-to-couchbase-part-2\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.couchbase.com\/blog\/migrating-from-mongodb-to-couchbase-part-2\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.couchbase.com\/blog\/migrating-from-mongodb-to-couchbase-part-2\/#primaryimage\",\"url\":\"https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2019\/07\/mongo-to-couchbase.png\",\"contentUrl\":\"https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2019\/07\/mongo-to-couchbase.png\",\"width\":1100,\"height\":389},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.couchbase.com\/blog\/migrating-from-mongodb-to-couchbase-part-2\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/www.couchbase.com\/blog\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Migrating Data from MongoDB to Couchbase, Part 2\"}]},{\"@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\/7fdd6feab8e25100caf61bb7836ee0ff\",\"name\":\"Douglas Bonser, Principal Solution Engineer, Couchbase\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.couchbase.com\/blog\/#\/schema\/person\/image\/e922810e11bd43dd211ba0ee960f9738\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/68f7547e24c39852e700940d8209edf75f6b9cd64ba057ce1e11313d9230ab84?s=96&d=mm&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/68f7547e24c39852e700940d8209edf75f6b9cd64ba057ce1e11313d9230ab84?s=96&d=mm&r=g\",\"caption\":\"Douglas Bonser, Principal Solution Engineer, Couchbase\"},\"description\":\"Douglas Bonser is a Principal Solutions Engineer at Couchbase and has been working in IT and technology since 1991. He is based in the Dallas\/Ft. Worth area.\",\"url\":\"https:\/\/www.couchbase.com\/blog\/author\/douglas-bonsercouchbase-com\/\"}]}<\/script>\n<!-- \/ Yoast SEO Premium plugin. -->","yoast_head_json":{"title":"Migrating Data from MongoDB to Couchbase, Part 2 - 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\/migrating-from-mongodb-to-couchbase-part-2\/","og_locale":"en_US","og_type":"article","og_title":"Migrating Data from MongoDB to Couchbase, Part 2","og_description":"Prolog The previous article provided details on how to migrate a MongoDB data set to Couchbase Server. This article shows you how to use the Couchbase SDK to access the data via a Java console application. Code snippets show how [&hellip;]","og_url":"https:\/\/www.couchbase.com\/blog\/migrating-from-mongodb-to-couchbase-part-2\/","og_site_name":"The Couchbase Blog","article_published_time":"2020-07-31T05:04:49+00:00","article_modified_time":"2025-06-14T04:01:56+00:00","og_image":[{"width":1100,"height":389,"url":"https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2019\/07\/mongo-to-couchbase.png","type":"image\/png"}],"author":"Douglas Bonser, Principal Solution Engineer, Couchbase","twitter_card":"summary_large_image","twitter_misc":{"Written by":"Douglas Bonser, Principal Solution Engineer, Couchbase","Est. reading time":"7 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/www.couchbase.com\/blog\/migrating-from-mongodb-to-couchbase-part-2\/#article","isPartOf":{"@id":"https:\/\/www.couchbase.com\/blog\/migrating-from-mongodb-to-couchbase-part-2\/"},"author":{"name":"Douglas Bonser, Principal Solution Engineer, Couchbase","@id":"https:\/\/www.couchbase.com\/blog\/#\/schema\/person\/7fdd6feab8e25100caf61bb7836ee0ff"},"headline":"Migrating Data from MongoDB to Couchbase, Part 2","datePublished":"2020-07-31T05:04:49+00:00","dateModified":"2025-06-14T04:01:56+00:00","mainEntityOfPage":{"@id":"https:\/\/www.couchbase.com\/blog\/migrating-from-mongodb-to-couchbase-part-2\/"},"wordCount":1179,"commentCount":0,"publisher":{"@id":"https:\/\/www.couchbase.com\/blog\/#organization"},"image":{"@id":"https:\/\/www.couchbase.com\/blog\/migrating-from-mongodb-to-couchbase-part-2\/#primaryimage"},"thumbnailUrl":"https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2019\/07\/mongo-to-couchbase.png","keywords":["6.5","API","Index","mongodb"],"articleSection":["Best Practices and Tutorials","Couchbase Server","Java","SQL++ \/ N1QL Query","Tools &amp; SDKs"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/www.couchbase.com\/blog\/migrating-from-mongodb-to-couchbase-part-2\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/www.couchbase.com\/blog\/migrating-from-mongodb-to-couchbase-part-2\/","url":"https:\/\/www.couchbase.com\/blog\/migrating-from-mongodb-to-couchbase-part-2\/","name":"Migrating Data from MongoDB to Couchbase, Part 2 - The Couchbase Blog","isPartOf":{"@id":"https:\/\/www.couchbase.com\/blog\/#website"},"primaryImageOfPage":{"@id":"https:\/\/www.couchbase.com\/blog\/migrating-from-mongodb-to-couchbase-part-2\/#primaryimage"},"image":{"@id":"https:\/\/www.couchbase.com\/blog\/migrating-from-mongodb-to-couchbase-part-2\/#primaryimage"},"thumbnailUrl":"https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2019\/07\/mongo-to-couchbase.png","datePublished":"2020-07-31T05:04:49+00:00","dateModified":"2025-06-14T04:01:56+00:00","breadcrumb":{"@id":"https:\/\/www.couchbase.com\/blog\/migrating-from-mongodb-to-couchbase-part-2\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.couchbase.com\/blog\/migrating-from-mongodb-to-couchbase-part-2\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.couchbase.com\/blog\/migrating-from-mongodb-to-couchbase-part-2\/#primaryimage","url":"https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2019\/07\/mongo-to-couchbase.png","contentUrl":"https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2019\/07\/mongo-to-couchbase.png","width":1100,"height":389},{"@type":"BreadcrumbList","@id":"https:\/\/www.couchbase.com\/blog\/migrating-from-mongodb-to-couchbase-part-2\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.couchbase.com\/blog\/"},{"@type":"ListItem","position":2,"name":"Migrating Data from MongoDB to Couchbase, Part 2"}]},{"@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\/7fdd6feab8e25100caf61bb7836ee0ff","name":"Douglas Bonser, Principal Solution Engineer, Couchbase","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.couchbase.com\/blog\/#\/schema\/person\/image\/e922810e11bd43dd211ba0ee960f9738","url":"https:\/\/secure.gravatar.com\/avatar\/68f7547e24c39852e700940d8209edf75f6b9cd64ba057ce1e11313d9230ab84?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/68f7547e24c39852e700940d8209edf75f6b9cd64ba057ce1e11313d9230ab84?s=96&d=mm&r=g","caption":"Douglas Bonser, Principal Solution Engineer, Couchbase"},"description":"Douglas Bonser is a Principal Solutions Engineer at Couchbase and has been working in IT and technology since 1991. He is based in the Dallas\/Ft. Worth area.","url":"https:\/\/www.couchbase.com\/blog\/author\/douglas-bonsercouchbase-com\/"}]}},"authors":[{"term_id":9091,"user_id":1352,"is_guest":0,"slug":"douglas-bonsercouchbase-com","display_name":"Douglas Bonser, Principal Solution Engineer, Couchbase","avatar_url":"https:\/\/secure.gravatar.com\/avatar\/68f7547e24c39852e700940d8209edf75f6b9cd64ba057ce1e11313d9230ab84?s=96&d=mm&r=g","author_category":"","last_name":"Bonser, Principal Solution Engineer, Couchbase","first_name":"Douglas","job_title":"","user_url":"","description":"Douglas Bonser is a Principal Solutions Engineer at Couchbase and has been working in IT and technology since 1991. He is based in the Dallas\/Ft. Worth area."}],"_links":{"self":[{"href":"https:\/\/www.couchbase.com\/blog\/wp-json\/wp\/v2\/posts\/7770","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\/1352"}],"replies":[{"embeddable":true,"href":"https:\/\/www.couchbase.com\/blog\/wp-json\/wp\/v2\/comments?post=7770"}],"version-history":[{"count":0,"href":"https:\/\/www.couchbase.com\/blog\/wp-json\/wp\/v2\/posts\/7770\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.couchbase.com\/blog\/wp-json\/wp\/v2\/media\/7289"}],"wp:attachment":[{"href":"https:\/\/www.couchbase.com\/blog\/wp-json\/wp\/v2\/media?parent=7770"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.couchbase.com\/blog\/wp-json\/wp\/v2\/categories?post=7770"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.couchbase.com\/blog\/wp-json\/wp\/v2\/tags?post=7770"},{"taxonomy":"author","embeddable":true,"href":"https:\/\/www.couchbase.com\/blog\/wp-json\/wp\/v2\/ppma_author?post=7770"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}