{"id":20,"date":"2022-02-02T23:51:01","date_gmt":"2022-02-02T23:51:01","guid":{"rendered":"https:\/\/blogs.oregonstate.edu\/dannytran\/?p=20"},"modified":"2022-02-02T23:51:01","modified_gmt":"2022-02-02T23:51:01","slug":"your-day-1-mongodb-quick-guide","status":"publish","type":"post","link":"https:\/\/blogs.oregonstate.edu\/dannytran\/2022\/02\/02\/your-day-1-mongodb-quick-guide\/","title":{"rendered":"Your Day 1 MongoDB Quick Guide"},"content":{"rendered":"\n<p>For my capstone project, we were assigned to work on an a client&#8217;s existing codebase. They were using MongoDB for their database so I spent some time researching how to get started as quick as possible.<\/p>\n\n\n\n<p>First find out which product of MongoDB the project is using. There are different offerings of MongoDB: Atlas (the cloud version) and Server. MongoDB Server can be access on the command line through a mongo shell. The command to access the shell is either mongo or mongosh (in beta). This might be the hardest part, and different for every project so you&#8217;d probably have to ask your senior engineer on how to start the database in order to access the shell. Since our database was on a Docker image, after starting the database, the command to access the shell was &#8216;docker exec -it db mongo&#8217;.<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"484\" height=\"347\" src=\"https:\/\/osu-wams-blogs-uploads.s3.amazonaws.com\/blogs.dir\/5143\/files\/2022\/02\/image-1.png\" alt=\"\" class=\"wp-image-22\" srcset=\"https:\/\/osu-wams-blogs-uploads.s3.amazonaws.com\/blogs.dir\/5143\/files\/2022\/02\/image-1.png 484w, https:\/\/osu-wams-blogs-uploads.s3.amazonaws.com\/blogs.dir\/5143\/files\/2022\/02\/image-1-300x215.png 300w\" sizes=\"auto, (max-width: 484px) 100vw, 484px\" \/><figcaption>Accessing the mongo shell<\/figcaption><\/figure>\n\n\n\n<p>This is what the mongo shell looks like, from here you use the &#8216;show dbs&#8217; command to display which databases the project is connected to. To switch to a specific database, type the name of it in this command &#8216;use &lt;database&gt;&#8217;. <\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"229\" height=\"89\" src=\"https:\/\/osu-wams-blogs-uploads.s3.amazonaws.com\/blogs.dir\/5143\/files\/2022\/02\/image-2.png\" alt=\"\" class=\"wp-image-23\" \/><figcaption>This database is named bookdb<\/figcaption><\/figure>\n\n\n\n<p>Each database should have a bunch of collections. MongoDB stores information in documents and a group of documents is called a collection. To see your collections use &#8216;show collections&#8217; or &#8216;db.getCollectionNames()&#8217; to see all the collections. Finally to see all the documents inside a collection, type the collection&#8217;s name using &#8216;db.&lt;collection_name&gt;.find({})&#8221;. This command is essentially &#8216;select * from table&#8217; from SQL. <\/p>\n\n\n\n<p>Hopefully from this quick guide, you can access the project&#8217;s database so you can start creating new collections or updating existing ones. From here you want to learn some of the CRUD commands. Here&#8217;s the one that I <a href=\"https:\/\/gist.github.com\/michaeltreat\/d3bdc989b54cff969df86484e091fd0c\">reference<\/a> from. <\/p>\n","protected":false},"excerpt":{"rendered":"<p>For my capstone project, we were assigned to work on an a client&#8217;s existing codebase. They were using MongoDB for their database so I spent some time researching how to get started as quick as possible. First find out which product of MongoDB the project is using. There are different offerings of MongoDB: Atlas (the&hellip; <a class=\"more-link\" href=\"https:\/\/blogs.oregonstate.edu\/dannytran\/2022\/02\/02\/your-day-1-mongodb-quick-guide\/\">Continue reading <span class=\"screen-reader-text\">Your Day 1 MongoDB Quick Guide<\/span><\/a><\/p>\n","protected":false},"author":11986,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-20","post","type-post","status-publish","format-standard","hentry","category-uncategorized","entry"],"_links":{"self":[{"href":"https:\/\/blogs.oregonstate.edu\/dannytran\/wp-json\/wp\/v2\/posts\/20","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blogs.oregonstate.edu\/dannytran\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blogs.oregonstate.edu\/dannytran\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blogs.oregonstate.edu\/dannytran\/wp-json\/wp\/v2\/users\/11986"}],"replies":[{"embeddable":true,"href":"https:\/\/blogs.oregonstate.edu\/dannytran\/wp-json\/wp\/v2\/comments?post=20"}],"version-history":[{"count":1,"href":"https:\/\/blogs.oregonstate.edu\/dannytran\/wp-json\/wp\/v2\/posts\/20\/revisions"}],"predecessor-version":[{"id":24,"href":"https:\/\/blogs.oregonstate.edu\/dannytran\/wp-json\/wp\/v2\/posts\/20\/revisions\/24"}],"wp:attachment":[{"href":"https:\/\/blogs.oregonstate.edu\/dannytran\/wp-json\/wp\/v2\/media?parent=20"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blogs.oregonstate.edu\/dannytran\/wp-json\/wp\/v2\/categories?post=20"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blogs.oregonstate.edu\/dannytran\/wp-json\/wp\/v2\/tags?post=20"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}