{"id":3157,"date":"2017-04-06T08:08:51","date_gmt":"2017-04-06T15:08:51","guid":{"rendered":"https:\/\/www.couchbase.com\/blog\/?p=3157"},"modified":"2020-10-28T08:33:16","modified_gmt":"2020-10-28T15:33:16","slug":"import-mongodb-collection-data-couchbase-server-golang","status":"publish","type":"post","link":"https:\/\/www.couchbase.com\/blog\/import-mongodb-collection-data-couchbase-server-golang\/","title":{"rendered":"Import Your MongoDB Collection Data into Couchbase Server with Golang"},"content":{"rendered":"<p>If you&#8217;ve been keeping up, you&#8217;ll remember I wrote a few tutorials around converting your MongoDB powered Node.js applications to Couchbase. \u00a0These included a <a href=\"https:\/\/www.couchbase.com\/blog\/moving-node-js-mongodb-application-couchbase-n1ql\/\" target=\"_blank\" rel=\"noopener noreferrer\">MongoDB Query Language to N1QL<\/a> tutorial as well as a <a href=\"https:\/\/www.couchbase.com\/blog\/migrating-mongodb-mongoose-restful-api-couchbase-ottoman\/\" target=\"_blank\" rel=\"noopener noreferrer\">Mongoose to Ottoman<\/a> tutorial. \u00a0These were great migration tutorials from an application perspective, but they didn&#8217;t really tell you how to get your existing Collections from MongoDB imported as JSON files.<\/p>\n<p>So, in this tutorial, we&#8217;re going to explore how to import MongoDB collection data into Couchbase. \u00a0The development language doesn&#8217;t really matter, but Golang is very fast and very powerful making it a perfect candidate for the job.<\/p>\n<p><!--more--><\/p>\n<p>Before we worry about writing a data migration script, let&#8217;s figure out a sample dataset that we&#8217;re working with. \u00a0The goal here is to be universal in our script, but it does help to have an example.<\/p>\n<h2>The MongoDB Collection Model<\/h2>\n<p>Let&#8217;s assume we have a Collection called\u00a0<strong>courses<\/strong> that holds information about courses offered by a school. \u00a0The document model for any one of these documents might look something like the following:<\/p>\n<pre class=\"lang:default highlight:0 decode:true \">{\r\n    \"name\": \"Basket Weaving 101\",\r\n    \"students\": [\r\n        \"nraboy\",\r\n        \"mgroves\",\r\n        \"hgreeley\"\r\n    ]\r\n}<\/pre>\n<p>Each document would represent a single course with a list of enrolled students. \u00a0Each document has an id value and the enrolled students reference documents from another collection with matching id values.<\/p>\n<p>With MongoDB installed you have access to its <a href=\"https:\/\/docs.mongodb.com\/manual\/reference\/program\/mongoexport\/\" target=\"_blank\" rel=\"noopener noreferrer\">mongoexport<\/a> utility. \u00a0This will allow us to export the documents that exist in any Collection to a JSON data file.<\/p>\n<p>For example, we could run the following command against our MongoDB database:<\/p>\n<pre class=\"lang:default highlight:0 decode:true \">mongoexport --db example --collection courses --out courses.json<\/pre>\n<p>The database in question would be\u00a0<code>example<\/code> and we&#8217;re exporting the\u00a0<code>courses<\/code> collection to a file called\u00a0<strong>courses.json<\/strong>. \u00a0If we try to open this JSON file, we&#8217;d see data that looks similar to the following:<\/p>\n<pre class=\"lang:default highlight:0 decode:true \">{\"_id\":{\"$oid\":\"course-1\"},\"name\":\"Basket Weaving 101\",\"students\":[{\"$oid\":\"nraboy\"},{\"$oid\":\"mgroves\"}]}\r\n{\"_id\":{\"$oid\":\"course-2\"},\"name\":\"TV Watching 101\",\"students\":[{\"$oid\":\"jmichaels\"},{\"$oid\":\"tgreenstein\"}]}<\/pre>\n<p>Each document will be a new line in the file, however it won&#8217;t be exactly how our schema was modeled. MongoDB will take all document references and wrap them in an <code>$oid<\/code> property which represents an object id.<\/p>\n<p>So where does this leave us?<\/p>\n<h2>Planning the Couchbase Bucket Model<\/h2>\n<p>As you&#8217;re probably already aware, Couchbase does not use Collections, but instead Buckets. \u00a0However, Buckets do not function the same as Collections. \u00a0Instead of having one Bucket per every one document type like MongoDB does, you&#8217;ll have one Bucket for every application.<\/p>\n<p>This means we&#8217;ll need to make some changes to MongoDB export so it makes any kind of sense inside of Couchbase.<\/p>\n<p>In Couchbase it is normal to have a document property in every document that represents the type of document it is. \u00a0Lucky for us we know the name of the former Collection and can work some magic. \u00a0As an end result our Couchbase documents should look something like this:<\/p>\n<pre class=\"lang:default highlight:0 decode:true \">{\r\n    \"_id\": \"course-1\",\r\n    \"_type\": \"courses\",\r\n    \"name\": \"Basket Weaving 101\",\r\n    \"students\": [\r\n        \"nraboy\",\r\n        \"mgroves\",\r\n        \"hgreeley\"\r\n    ]\r\n}<\/pre>\n<p>In the above example we have compressed all the\u00a0<code>$oid<\/code> values and added the\u00a0<code>_id<\/code> and\u00a0<code>_type<\/code> properties.<\/p>\n<h2>Developing the Golang Collection Import Script<\/h2>\n<p>Now that we know where we&#8217;re headed, we can focus on the script that will do the manipulations and loading. \u00a0However, let&#8217;s think about our Golang logic on how to accomplish the job.<\/p>\n<p>We know we&#8217;re going to be reading line by line from a JSON file. \u00a0For every line read we need to manipulate it, then save it. \u00a0Reading from a file and inserting into Couchbase are both blocking operations. \u00a0While reading is quite fast, inserting a single document at a time in a blocking fashion for terabytes of data can be quite slow. \u00a0This means we should start goroutines to do things in parallel.<\/p>\n<p>Create a new project somewhere in your\u00a0<strong>$GOPATH<\/strong> and create a file called\u00a0<strong>main.go<\/strong> with the following code:<\/p>\n<pre class=\"lang:default highlight:0 decode:true \">package main\r\n\r\nimport (\r\n\t\"bufio\"\r\n\t\"encoding\/json\"\r\n\t\"flag\"\r\n\t\"fmt\"\r\n\t\"os\"\r\n\t\"sync\"\r\n\r\n\t\"github.com\/couchbase\/gocb\"\r\n)\r\n\r\nvar waitGroup sync.WaitGroup\r\nvar data chan string\r\nvar bucket *gocb.Bucket\r\n\r\nfunc main() {}\r\n\r\nfunc worker(collection string) {}\r\n\r\nfunc cbimport(document string, collection string) {}\r\n\r\nfunc compressObjectIds(mapDocument map[string]interface{}) string {}<\/pre>\n<p>The above code is merely a blueprint to what we&#8217;re going to accomplish. \u00a0The\u00a0<code>main<\/code> function will be responsible for starting several goroutines and reading our JSON file. \u00a0We don&#8217;t want the application to end when the\u00a0<code>main<\/code> function ends so we use a <a href=\"https:\/\/golang.org\/pkg\/sync\/\" target=\"_blank\" rel=\"noopener noreferrer\">WaitGroup<\/a>. \u00a0This will prevent the application from ending until all goroutines have ended.<\/p>\n<p>The\u00a0<code>worker<\/code> function will be each goroutine and it will call\u00a0<code>cbimport<\/code> which will call\u00a0<code>compressObjectIds<\/code> to swap out any\u00a0<code>$oid<\/code> with the compressed equivalent. \u00a0By compressed I mean won&#8217;t include a wrapping\u00a0<code>$oid<\/code> property.<\/p>\n<p>So let&#8217;s look at that\u00a0<code>main<\/code> function:<\/p>\n<pre class=\"lang:default highlight:0 decode:true \">func main() {\r\n\tfmt.Println(\"Starting the import process...\")\r\n\r\n\tflagInputFile := flag.String(\"input-file\", \"\", \"file with path which contains documents\")\r\n\tflagWorkerCount := flag.Int(\"workers\", 20, \"concurrent workers for importing data\")\r\n\tflagCollectionName := flag.String(\"collection\", \"\", \"mongodb collection name\")\r\n\tflagCouchbaseHost := flag.String(\"couchbase-host\", \"\", \"couchbase cluster host\")\r\n\tflagCouchbaseBucket := flag.String(\"couchbase-bucket\", \"\", \"couchbase bucket name\")\r\n\tflagCouchbaseBucketPassword := flag.String(\"couchbase-bucket-password\", \"\", \"couchbase bucket password\")\r\n\tflag.Parse()\r\n\r\n\tcluster, _ := gocb.Connect(\"couchbase:\/\/\" + *flagCouchbaseHost)\r\n\tbucket, _ = cluster.OpenBucket(*flagCouchbaseBucket, *flagCouchbaseBucketPassword)\r\n\r\n\tfile, _ := os.Open(*flagInputFile)\r\n\tdefer file.Close()\r\n\r\n\tdata = make(chan string)\r\n\r\n\tscanner := bufio.NewScanner(file)\r\n\tscanner.Split(bufio.ScanLines)\r\n\r\n\tfor i := 0; i &lt; *flagWorkerCount; i++ {\r\n\t\twaitGroup.Add(1)\r\n\t\tgo worker(*flagCollectionName)\r\n\t}\r\n\r\n\tfor scanner.Scan() {\r\n\t\tdata &lt;- scanner.Text()\r\n\t}\r\n\r\n\tclose(data)\r\n\r\n\twaitGroup.Wait()\r\n\r\n\tfmt.Println(\"The import has completed!\")\r\n}<\/pre>\n<p>The above function will take a set of command line flags that will be used in the configuration of the application. \u00a0The connection to the destination Couchbase Server and Bucket will be established and the input file will be opened.<\/p>\n<p>Because we&#8217;re using goroutines, we need to use channel variables to avoid locking scenarios. \u00a0All lines read will be queued up in the channel where each goroutine will read from.<\/p>\n<p>After spinning up the goroutines, the file will be read and the channel will be populated. \u00a0After the file is completely read, the channel will close. \u00a0This means that when the goroutines read all the data, the goroutines will be able to end. \u00a0We&#8217;ll be waiting until the goroutines end before ending the application.<\/p>\n<p>Now let&#8217;s take a look at the\u00a0<code>worker<\/code> function:<\/p>\n<pre class=\"lang:default highlight:0 decode:true \">func worker(collection string) {\r\n\tdefer waitGroup.Done()\r\n\tfor {\r\n\t\tdocument, ok := &lt;-data\r\n\t\tif !ok {\r\n\t\t\tbreak\r\n\t\t}\r\n\t\tcbimport(document, collection)\r\n\t}\r\n}<\/pre>\n<p>The MongoDB Collection name will be passed to each worker and the worker will remain functional in a loop until the channel closes.<\/p>\n<p>For every document read from the channel, the\u00a0<code>cbimport<\/code> function will be called:<\/p>\n<pre class=\"lang:default highlight:0 decode:true \">func cbimport(document string, collection string) {\r\n\tvar mapDocument map[string]interface{}\r\n\tjson.Unmarshal([]byte(document), &amp;mapDocument)\r\n\tmapDocument[\"_type\"] = collection\r\n\tcompressObjectIds(mapDocument)\r\n\tbucket.Insert(mapDocument[\"_id\"].(string), mapDocument, 0)\r\n}<\/pre>\n<p>Each line of the file will be a string that we need to unmarshal into a map of interfaces. \u00a0We know the Collection name, so we can create a property that will hold that particular name. \u00a0Then we can pass the entire map into the\u00a0<code>compressObjectIds<\/code> function to get rid of any\u00a0<code>$oid<\/code> wrappers.<\/p>\n<p>The\u00a0<code>compressObjectIds<\/code> function looks like the following:<\/p>\n<pre class=\"lang:default highlight:0 decode:true \">func compressObjectIds(mapDocument map[string]interface{}) string {\r\n\tvar objectIdValue string\r\n\tfor key, value := range mapDocument {\r\n\t\tswitch value.(type) {\r\n\t\tcase string:\r\n\t\t\tif key == \"$oid\" &amp;&amp; len(mapDocument) == 1 {\r\n\t\t\t\treturn value.(string)\r\n\t\t\t}\r\n\t\tcase map[string]interface{}:\r\n\t\t\tobjectIdValue = compressObjectIds(value.(map[string]interface{}))\r\n\t\t\tif objectIdValue != \"\" {\r\n\t\t\t\tmapDocument[key] = objectIdValue\r\n\t\t\t}\r\n\t\tcase []interface{}:\r\n\t\t\tfor index, element := range value.([]interface{}) {\r\n\t\t\t\tobjectIdValue = compressObjectIds(element.(map[string]interface{}))\r\n\t\t\t\tif objectIdValue != \"\" {\r\n\t\t\t\t\tvalue.([]interface{})[index] = objectIdValue\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t}\r\n\t}\r\n\treturn \"\"\r\n}<\/pre>\n<p>In the above we are essentially looping through every key in the document. \u00a0If the value is a nested object or JSON array, we recursively do the same thing until we hit a string with a key of <code>$oid<\/code>. \u00a0If this condition is met we make sure it is the only key in that level of the document. \u00a0This will let us know that it is an id that we can safely compress.<\/p>\n<p>Not so bad right?<\/p>\n<h2>Running the MongoDB to Couchbase Importer<\/h2>\n<p>Assuming you have the Go programming language installed and configured, we need to build this application.<\/p>\n<p>From the command line, you&#8217;ll need to get all the dependencies. \u00a0With the project as your current working directory, execute the following:<\/p>\n<pre class=\"lang:default highlight:0 decode:true \">go get -d -v<\/pre>\n<p>The above command will get any dependencies found in our Go files.<\/p>\n<p>Now the application can be built and ran, or just ran. \u00a0The steps aren&#8217;t really any different, but we&#8217;re just going to run the code.<\/p>\n<p>From the command line, execute the following:<\/p>\n<pre class=\"lang:default highlight:0 decode:true \">.\/collectionimport \\\r\n    --input-file FILE_NAME.json \\\r\n    --collection COLLECTION_NAME \\\r\n    --couchbase-host localhost \\\r\n    --couchbase-bucket default \\\r\n    --workers 20<\/pre>\n<p>The above command will allow us to pass any flags into the application such as Couchbase Server information, number of worker goroutines, etc.<\/p>\n<p>If successful, the MongoDB export should now be present in your Couchbase NoSQL database.<\/p>\n<h2>Conclusion<\/h2>\n<p>You just saw how to work with Golang and MongoDB to import your collections data into Couchbase. \u00a0Sure the code we saw can be optimized, but from a simplicity standpoint I&#8217;m sure you can see what we were trying to accomplish.<\/p>\n<p>Want to download this importer project and try it out for yourself? \u00a0I&#8217;ve gone and uploaded it to <a href=\"https:\/\/github.com\/couchbaselabs\/collectionimport\" target=\"_blank\" rel=\"noopener noreferrer\">GitHub<\/a>, with further instructions for running. \u00a0Keep in mind that it is unofficial and hasn&#8217;t been tested for massive amounts of data. \u00a0Treat it as an example for learning how to meet your data migration needs.<\/p>\n<p>If you&#8217;re interested in learning more about Couchbase Server or the Golang SDK, check out the <a href=\"https:\/\/developer.couchbase.com\" target=\"_blank\" rel=\"noopener noreferrer\">Couchbase Developer Portal<\/a>.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>If you&#8217;ve been keeping up, you&#8217;ll remember I wrote a few tutorials around converting your MongoDB powered Node.js applications to Couchbase. \u00a0These included a MongoDB Query Language to N1QL tutorial as well as a Mongoose to Ottoman tutorial. \u00a0These were [&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":[1815,1816,1820],"tags":[1933,1866,1931,1502,1579,1934,1935],"ppma_author":[9032],"class_list":["post-3157","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-best-practices-and-tutorials","category-couchbase-server","category-golang","tag-backup","tag-data","tag-export","tag-import","tag-parse","tag-restore","tag-script"],"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>Import Your MongoDB Collection Data into Couchbase Server with Golang<\/title>\n<meta name=\"description\" content=\"Learn how to migrate your MongoDB Collection data into Couchbase Server with the mongoexport CLI and a very simple Golang script.\" \/>\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\/import-mongodb-collection-data-couchbase-server-golang\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Import Your MongoDB Collection Data into Couchbase Server with Golang\" \/>\n<meta property=\"og:description\" content=\"Learn how to migrate your MongoDB Collection data into Couchbase Server with the mongoexport CLI and a very simple Golang script.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.couchbase.com\/blog\/import-mongodb-collection-data-couchbase-server-golang\/\" \/>\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=\"2017-04-06T15:08:51+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2020-10-28T15:33:16+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/2022\/11\/couchbase-nosql-dbaas.png\" \/>\n\t<meta property=\"og:image:width\" content=\"1800\" \/>\n\t<meta property=\"og:image:height\" content=\"630\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/png\" \/>\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=\"8 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/www.couchbase.com\/blog\/import-mongodb-collection-data-couchbase-server-golang\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/www.couchbase.com\/blog\/import-mongodb-collection-data-couchbase-server-golang\/\"},\"author\":{\"name\":\"Nic Raboy, Developer Advocate, Couchbase\",\"@id\":\"https:\/\/www.couchbase.com\/blog\/#\/schema\/person\/bb545ebe83bb2d12f91095811d0a72e1\"},\"headline\":\"Import Your MongoDB Collection Data into Couchbase Server with Golang\",\"datePublished\":\"2017-04-06T15:08:51+00:00\",\"dateModified\":\"2020-10-28T15:33:16+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/www.couchbase.com\/blog\/import-mongodb-collection-data-couchbase-server-golang\/\"},\"wordCount\":1263,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\/\/www.couchbase.com\/blog\/#organization\"},\"image\":{\"@id\":\"https:\/\/www.couchbase.com\/blog\/import-mongodb-collection-data-couchbase-server-golang\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2022\/11\/couchbase-nosql-dbaas.png\",\"keywords\":[\"backup\",\"data\",\"export\",\"import\",\"parse\",\"restore\",\"script\"],\"articleSection\":[\"Best Practices and Tutorials\",\"Couchbase Server\",\"GoLang\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\/\/www.couchbase.com\/blog\/import-mongodb-collection-data-couchbase-server-golang\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.couchbase.com\/blog\/import-mongodb-collection-data-couchbase-server-golang\/\",\"url\":\"https:\/\/www.couchbase.com\/blog\/import-mongodb-collection-data-couchbase-server-golang\/\",\"name\":\"Import Your MongoDB Collection Data into Couchbase Server with Golang\",\"isPartOf\":{\"@id\":\"https:\/\/www.couchbase.com\/blog\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/www.couchbase.com\/blog\/import-mongodb-collection-data-couchbase-server-golang\/#primaryimage\"},\"image\":{\"@id\":\"https:\/\/www.couchbase.com\/blog\/import-mongodb-collection-data-couchbase-server-golang\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2022\/11\/couchbase-nosql-dbaas.png\",\"datePublished\":\"2017-04-06T15:08:51+00:00\",\"dateModified\":\"2020-10-28T15:33:16+00:00\",\"description\":\"Learn how to migrate your MongoDB Collection data into Couchbase Server with the mongoexport CLI and a very simple Golang script.\",\"breadcrumb\":{\"@id\":\"https:\/\/www.couchbase.com\/blog\/import-mongodb-collection-data-couchbase-server-golang\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.couchbase.com\/blog\/import-mongodb-collection-data-couchbase-server-golang\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.couchbase.com\/blog\/import-mongodb-collection-data-couchbase-server-golang\/#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\/import-mongodb-collection-data-couchbase-server-golang\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/www.couchbase.com\/blog\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Import Your MongoDB Collection Data into Couchbase Server with Golang\"}]},{\"@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\/bb545ebe83bb2d12f91095811d0a72e1\",\"name\":\"Nic Raboy, Developer Advocate, Couchbase\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.couchbase.com\/blog\/#\/schema\/person\/image\/8863514d8bed0cf6080f23db40e00354\",\"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\/author\/nic-raboy-2\/\"}]}<\/script>\n<!-- \/ Yoast SEO Premium plugin. -->","yoast_head_json":{"title":"Import Your MongoDB Collection Data into Couchbase Server with Golang","description":"Learn how to migrate your MongoDB Collection data into Couchbase Server with the mongoexport CLI and a very simple Golang script.","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\/import-mongodb-collection-data-couchbase-server-golang\/","og_locale":"en_US","og_type":"article","og_title":"Import Your MongoDB Collection Data into Couchbase Server with Golang","og_description":"Learn how to migrate your MongoDB Collection data into Couchbase Server with the mongoexport CLI and a very simple Golang script.","og_url":"https:\/\/www.couchbase.com\/blog\/import-mongodb-collection-data-couchbase-server-golang\/","og_site_name":"The Couchbase Blog","article_author":"https:\/\/www.facebook.com\/thepolyglotdeveloper","article_published_time":"2017-04-06T15:08:51+00:00","article_modified_time":"2020-10-28T15:33:16+00:00","og_image":[{"width":1800,"height":630,"url":"https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/2022\/11\/couchbase-nosql-dbaas.png","type":"image\/png"}],"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":"8 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/www.couchbase.com\/blog\/import-mongodb-collection-data-couchbase-server-golang\/#article","isPartOf":{"@id":"https:\/\/www.couchbase.com\/blog\/import-mongodb-collection-data-couchbase-server-golang\/"},"author":{"name":"Nic Raboy, Developer Advocate, Couchbase","@id":"https:\/\/www.couchbase.com\/blog\/#\/schema\/person\/bb545ebe83bb2d12f91095811d0a72e1"},"headline":"Import Your MongoDB Collection Data into Couchbase Server with Golang","datePublished":"2017-04-06T15:08:51+00:00","dateModified":"2020-10-28T15:33:16+00:00","mainEntityOfPage":{"@id":"https:\/\/www.couchbase.com\/blog\/import-mongodb-collection-data-couchbase-server-golang\/"},"wordCount":1263,"commentCount":0,"publisher":{"@id":"https:\/\/www.couchbase.com\/blog\/#organization"},"image":{"@id":"https:\/\/www.couchbase.com\/blog\/import-mongodb-collection-data-couchbase-server-golang\/#primaryimage"},"thumbnailUrl":"https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2022\/11\/couchbase-nosql-dbaas.png","keywords":["backup","data","export","import","parse","restore","script"],"articleSection":["Best Practices and Tutorials","Couchbase Server","GoLang"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/www.couchbase.com\/blog\/import-mongodb-collection-data-couchbase-server-golang\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/www.couchbase.com\/blog\/import-mongodb-collection-data-couchbase-server-golang\/","url":"https:\/\/www.couchbase.com\/blog\/import-mongodb-collection-data-couchbase-server-golang\/","name":"Import Your MongoDB Collection Data into Couchbase Server with Golang","isPartOf":{"@id":"https:\/\/www.couchbase.com\/blog\/#website"},"primaryImageOfPage":{"@id":"https:\/\/www.couchbase.com\/blog\/import-mongodb-collection-data-couchbase-server-golang\/#primaryimage"},"image":{"@id":"https:\/\/www.couchbase.com\/blog\/import-mongodb-collection-data-couchbase-server-golang\/#primaryimage"},"thumbnailUrl":"https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2022\/11\/couchbase-nosql-dbaas.png","datePublished":"2017-04-06T15:08:51+00:00","dateModified":"2020-10-28T15:33:16+00:00","description":"Learn how to migrate your MongoDB Collection data into Couchbase Server with the mongoexport CLI and a very simple Golang script.","breadcrumb":{"@id":"https:\/\/www.couchbase.com\/blog\/import-mongodb-collection-data-couchbase-server-golang\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.couchbase.com\/blog\/import-mongodb-collection-data-couchbase-server-golang\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.couchbase.com\/blog\/import-mongodb-collection-data-couchbase-server-golang\/#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\/import-mongodb-collection-data-couchbase-server-golang\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.couchbase.com\/blog\/"},{"@type":"ListItem","position":2,"name":"Import Your MongoDB Collection Data into Couchbase Server with Golang"}]},{"@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\/bb545ebe83bb2d12f91095811d0a72e1","name":"Nic Raboy, Developer Advocate, Couchbase","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.couchbase.com\/blog\/#\/schema\/person\/image\/8863514d8bed0cf6080f23db40e00354","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\/author\/nic-raboy-2\/"}]}},"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","author_category":"","last_name":"Raboy","first_name":"Nic","job_title":"","user_url":"https:\/\/www.thepolyglotdeveloper.com","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."}],"_links":{"self":[{"href":"https:\/\/www.couchbase.com\/blog\/wp-json\/wp\/v2\/posts\/3157","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\/63"}],"replies":[{"embeddable":true,"href":"https:\/\/www.couchbase.com\/blog\/wp-json\/wp\/v2\/comments?post=3157"}],"version-history":[{"count":0,"href":"https:\/\/www.couchbase.com\/blog\/wp-json\/wp\/v2\/posts\/3157\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.couchbase.com\/blog\/wp-json\/wp\/v2\/media\/13873"}],"wp:attachment":[{"href":"https:\/\/www.couchbase.com\/blog\/wp-json\/wp\/v2\/media?parent=3157"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.couchbase.com\/blog\/wp-json\/wp\/v2\/categories?post=3157"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.couchbase.com\/blog\/wp-json\/wp\/v2\/tags?post=3157"},{"taxonomy":"author","embeddable":true,"href":"https:\/\/www.couchbase.com\/blog\/wp-json\/wp\/v2\/ppma_author?post=3157"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}