{"id":110894,"date":"2021-07-21T07:00:00","date_gmt":"2021-07-21T04:00:00","guid":{"rendered":"https:\/\/www.javacodegeeks.com\/?p=110894"},"modified":"2021-07-20T12:40:18","modified_gmt":"2021-07-20T09:40:18","slug":"node-js-and-mongodb-tutorial","status":"publish","type":"post","link":"https:\/\/www.javacodegeeks.com\/node-js-and-mongodb-tutorial.html","title":{"rendered":"Node.js and MongoDB Tutorial"},"content":{"rendered":"<p>Hello. In this tutorial, we will create a simple node.js application and perform the CRUD operations with the MongoDB.<\/p>\n<p>The node.js framework is commonly used to create server-based applications which are further used to show the contents to the users.\u00a0<\/p>\n<h2>1. Introduction<\/h2>\n<p>Let us first understand that what is Mongo database and set up Node.js.<\/p>\n<ul>\n<li>MongoDB is a high-performance <em>NoSQL database<\/em> where each database has collections that in turn have documents. Each document has a different number of fields, size, content, and is stored in a JSON-like format (i.e. Binary JSON (<a href=\"https:\/\/en.wikipedia.org\/wiki\/BSON\" target=\"_blank\" rel=\"noopener\">BSN<\/a>)<\/li>\n<li>The documents in MongoDB don\u2019t need to have a schema defined beforehand. Instead, the fields (i.e. <em>records<\/em>) can be created on the go<\/li>\n<li>Data model available within the MongoDB allows developers to represent the hierarchical relationships, store arrays, and other more complex structures easily<\/li>\n<li>This NoSQL solution often comes with embedding, auto-sharding, and onboard replication for better scalability and high availability<\/li>\n<\/ul>\n<h3>1.1 Setting up Node.js<\/h3>\n<p>To set up <strong>Node.js<\/strong> on windows you will need to download the installer from <a href=\"https:\/\/nodejs.org\/en\/download\/\" target=\"_blank\" rel=\"noopener\">this<\/a> link. Click on the installer (also include the NPM package manager) for your platform and run the installer to start with the Node.js setup wizard. Follow the wizard steps and click on Finish when it is done. If everything goes well you can navigate to the command prompt to verify if the installation was successful as shown in Fig. 1.<\/p>\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-large\"><a href=\"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2021\/07\/node-npm-installation-img1-1.jpg\"><img decoding=\"async\" width=\"480\" height=\"91\" src=\"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2021\/07\/node-npm-installation-img1-1.jpg\" alt=\"node js mongo db tutorial - npm intallation\" class=\"wp-image-110896\" srcset=\"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2021\/07\/node-npm-installation-img1-1.jpg 480w, https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2021\/07\/node-npm-installation-img1-1-300x57.jpg 300w\" sizes=\"(max-width: 480px) 100vw, 480px\" \/><\/a><figcaption>Fig. 1: Verifying node and npm installation<\/figcaption><\/figure>\n<\/div>\n<h2>2. Setting up Mongo database on Docker<\/h2>\n<p>To start with the tutorial, I am hoping that you have the Mongo database up and running in your local environment. For easy use, I will set it up in the <a href=\"https:\/\/examples.javacodegeeks.com\/docker-basic-commands\/\" target=\"_blank\" rel=\"noopener\">Docker<\/a> environment. You can use the below manifest file to get the container up and running in minutes. The file will also create an initial database named <code>employeedb<\/code>.<\/p>\n<p><span style=\"text-decoration: underline\"><em>stack.yml<\/em><\/span><\/p>\n<pre class=\"brush:plain; wrap-lines:false;\">services:\n  mongodb:\n    image: mongo\n    container_name: mongodb\n    environment:\n      MONGO_INITDB_DATABASE: employeedb\n    ports:\n      - \"27017:27017\"\nversion: \"3\"\n<\/pre>\n<p>To execute or stop\/remove the manifest file you can execute the below commands.<\/p>\n<p><span style=\"text-decoration: underline\"><em>Docker commands<\/em><\/span><\/p>\n<pre class=\"brush:plain; wrap-lines:false;\">-- start the container\ndocker-compose -f stack.yml up -d\n\n-- stop and remove the container\ndocker-compose -f stack.yml down\n<\/pre>\n<p>If everything goes well the container would be started successfully as shown in Fig. 2 and you can use the <code>docker ps -a<\/code> command to confirm.<\/p>\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-large\"><a href=\"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2021\/07\/docker-run.jpg\"><img decoding=\"async\" width=\"818\" height=\"113\" src=\"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2021\/07\/docker-run.jpg\" alt=\"node js mongo db tutorial - container status\" class=\"wp-image-110897\" srcset=\"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2021\/07\/docker-run.jpg 818w, https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2021\/07\/docker-run-300x41.jpg 300w, https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2021\/07\/docker-run-768x106.jpg 768w\" sizes=\"(max-width: 818px) 100vw, 818px\" \/><\/a><figcaption>Fig. 2: Verifying container status<\/figcaption><\/figure>\n<\/div>\n<h2>3. Node.js and MongoDB Tutorial<\/h2>\n<p>To set up the application, we will need to navigate to a path where our project will reside. For programming stuff, I am using <a href=\"https:\/\/code.visualstudio.com\/\" target=\"_blank\" rel=\"noopener\">Visual Studio Code<\/a> as my preferred IDE. You&#8217;re free to choose the IDE of your choice.<div style=\"display:inline-block; margin: 15px 0;\"> <div id=\"adngin-JavaCodeGeeks_incontent_video-0\" style=\"display:inline-block;\"><\/div> <\/div><\/p>\n<h3>3.1 Setting up dependencies<\/h3>\n<p>Navigate to the project directory and run <code>npm init -y<\/code> to create a <code>package.json<\/code> file. This <a href=\"https:\/\/docs.npmjs.com\/creating-a-package-json-file\" target=\"_blank\" rel=\"noopener\">file<\/a> holds the metadata relevant to the project and is used for managing the project dependencies, script, version, etc. Add the following code to the file wherein we will specify the required dependencies.<\/p>\n<p><span style=\"text-decoration: underline\"><em>package.json<\/em><\/span><\/p>\n<pre class=\"brush:json;\">{\n  \"name\": \"mongodb\",\n  \"version\": \"1.0.0\",\n  \"description\": \"nodejs and mongodb tutorial\",\n  \"main\": \"index.js\",\n  \"scripts\": {\n    \"test\": \"echo \\\"Error: no test specified\\\" &amp;&amp; exit 1\"\n  },\n  \"keywords\": [\n    \"nodejs\",\n    \"monogodb\",\n    \"docker\",\n    \"restapi\",\n    \"express\"\n  ],\n  \"author\": \"c-danielatlas\",\n  \"license\": \"MIT\",\n  \"devDependencies\": {\n    \"nodemon\": \"^2.0.11\"\n  },\n  \"dependencies\": {\n    \"body-parser\": \"^1.19.0\",\n    \"express\": \"^4.17.1\",\n    \"mongoose\": \"^5.13.2\"\n  }\n}\n<\/pre>\n<p>To download the dependencies navigate to the directory path containing the file and use the <code>npm install<\/code> command. If everything goes well the dependencies will be loaded inside the <code>node_modules<\/code> folder and you are good to go with the further steps.<\/p>\n<h3>3.2 Creating the model class<\/h3>\n<p>We will define the <code>Employee<\/code> model in mongoose. Create a new folder called <code>model<\/code> inside the root folder. Now create a file called <code>employee.js<\/code> with the following content. This model will represent a collection in the mongo database.<br \/><span style=\"text-decoration: underline\"><em>employee.js<\/em><\/span><\/p>\n<pre class=\"brush:js;\">const mongoose = require('mongoose');\n\nconst EmployeeSchema = mongoose.Schema({\n    first_name: {\n        type: String\n    },\n    last_name: {\n        type: String\n    },\n    email_address: {\n        type: String,\n        required: [true, 'Email address is required']\n    },\n    phone_number: {\n        type: String\n    },\n    date_of_joining: {\n        type: Date,\n        default: Date.now\n    }\n});\n\nmodule.exports = mongoose.model('Employees', EmployeeSchema);\n<\/pre>\n<h3>3.3 Creating the routes file<\/h3>\n<p>Create a new folder called <code>routes<\/code> inside the root folder. Now create a file called <code>employee.js<\/code> with the following content. The file will be responsible to handle the incoming HTTP requests from the client and perform the CRUD operations with the help of the mongoose model.<\/p>\n<p><span style=\"text-decoration: underline\"><em>employee.js<\/em><\/span><\/p>\n<pre class=\"brush:js;\">const express = require('express');\nconst router = express.Router();\nconst Employee = require('..\/models\/employee');\n\n\/\/ submit employee details\nrouter.post('\/', (req, res) =&gt; {\n    \/\/ todo - skipping request body validation for brevity\n\n    \/\/ creating employee obj\n    var employee = new Employee({\n        first_name: req.body.first_name,\n        last_name: req.body.last_name,\n        email_address: req.body.email_address,\n        phone_number: req.body.phone_number\n    });\n\n    employee.save()\n        .then((response) =&gt; {\n            res.status(201).json({ 'message': response });\n        }).catch(err =&gt; {\n            res.status(500).json({ 'message': err });\n        });\n});\n\n\/\/ get back all employees\nrouter.get('\/', (req, res) =&gt; {\n    Employee.find()\n        .then(response =&gt; {\n            res.status(200).json({ 'message': response });\n        }).catch(err =&gt; {\n            res.status(500).json({ 'message': err });\n        });\n});\n\n\/\/ get back a single employee\nrouter.get('\/:id', (req, res) =&gt; {\n    console.log('Searching id = %s', req.params.id);\n    Employee.findById(req.params.id)\n        .then(response =&gt; {\n            if (!response) {\n                res.status(404).json({ 'message': 'Resource not found' });\n            } else {\n                res.status(200).json({ 'message': response });\n            }\n        }).catch(err =&gt; {\n            res.status(500).json({ 'message': err });\n        });\n});\n\n\/\/ delete all employees\nrouter.delete('\/', (req, res) =&gt; {\n    Employee.deleteMany()\n        .then(response =&gt; {\n            res.status(200).json({ 'message': response });\n        }).catch(err =&gt; {\n            res.status(500).json({ 'message': err });\n        });\n});\n\n\/\/ delete an employee\nrouter.delete('\/:id', (req, res) =&gt; {\n    console.log('Deleting id = %s', req.params.id);\n\n    \/\/ todo - skipping find-by-id validation for brevity\n\n    Employee.deleteOne({ _id: req.params.id })\n        .then(response =&gt; {\n            res.status(200).json({ 'message': response });\n        }).catch(err =&gt; {\n            res.status(500).json({ 'message': err });\n        });\n});\n\n\/\/ update an employee\nrouter.patch('\/:id', (req, res) =&gt; {\n    console.log('Updating id = %s', req.params.id);\n\n    \/\/ todo - skipping find-by-id validation for brevity\n\n    Employee.updateOne(\n        { _id: req.params.id },\n        { $set: { phone_number: req.body.phone_number } })\n        .then(response =&gt; {\n            res.status(204).json({ 'message': response });\n        }).catch(err =&gt; {\n            res.status(500).json({ 'message': err });\n        });\n});\n\nmodule.exports = router;\n<\/pre>\n<h3>3.4 Setting up Express webserver<\/h3>\n<p>In the root folder add the following content to the <code>index.js<\/code> file.<\/p>\n<p><span style=\"text-decoration: underline\"><em>index.js<\/em><\/span><\/p>\n<pre class=\"brush:js;\">const express = require('express');\nconst app = express();\nconst bodyParser = require('body-parser');\nconst mongoose = require('mongoose');\n\n\/\/ parsing request of content-type as application\/json\napp.use(bodyParser.json());\n\n\/\/ import routes\nconst employeeRoutes = require('.\/routes\/employees');\napp.use('\/employees', employeeRoutes);\n\n\/\/ connect to db\nconst DB_CONNECTION = 'mongodb:\/\/localhost:27017\/employeedb';\nmongoose.connect(DB_CONNECTION, { useNewUrlParser: true, useUnifiedTopology: true })\n    .then(() =&gt; {\n        console.log('connected to db');\n    }).catch(err =&gt; {\n        console.log('error while connecting to db', err);\n    });\n\n\/\/ start app\nconst PORT = process.env.port || 3000;\napp.listen(PORT, () =&gt; {\n    console.log(`Server started on port ${PORT}`);\n});\n<\/pre>\n<h2>4. Run the Application<\/h2>\n<p>To run the application navigate to the project directory and enter the following command as shown in Fig. 2. If everything goes well the application will be started successfully on port number <code>3000<\/code>.<\/p>\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-large\"><a href=\"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2021\/07\/code-run-1.jpg\"><img decoding=\"async\" width=\"818\" height=\"170\" src=\"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2021\/07\/code-run-1.jpg\" alt=\"node js mongo db tutorial - starting the app\" class=\"wp-image-110898\" srcset=\"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2021\/07\/code-run-1.jpg 818w, https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2021\/07\/code-run-1-300x62.jpg 300w, https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2021\/07\/code-run-1-768x160.jpg 768w\" sizes=\"(max-width: 818px) 100vw, 818px\" \/><\/a><figcaption>Fig. 3: Starting the application<\/figcaption><\/figure>\n<\/div>\n<h2>5. Demo<\/h2>\n<p>You are free to use <a href=\"https:\/\/www.getpostman.com\/\" target=\"_blank\" rel=\"noopener\">postman<\/a> or any other tool of your choice to make the HTTP request to the application endpoints.<\/p>\n<pre class=\"brush:plain; wrap-lines:false;\">\/\/ submit employee details\n\/\/ HTTP post\n\/\/ Sample request body -\n\/\/ {\n\/\/     \"first_name\": \"John\",\n\/\/     \"last_name\": \"Doe\",\n\/\/     \"email_address\": \"john.doe@example.com\",\n\/\/     \"phone_number\": \"1234567890\"\n\/\/ }\nhttp:\/\/localhost:3000\/employees\/\n\n\/\/ get all employees\n\/\/ HTTP get\nhttp:\/\/localhost:3000\/employees\/\n\n\/\/ get a single employee\n\/\/ HTTP get\nhttp:\/\/localhost:3000\/employees\/60e9b70dbe4c540fa4c3bb21\n\n\/\/ update a single employee\n\/\/ HTTP patch\nhttp:\/\/localhost:3000\/employees\/60e9bea87f9c4640f0b27617\n\n\/\/ delete a single employee\n\/\/ HTTP delete\nhttp:\/\/localhost:3000\/employees\/60e9bea87f9c4640f0b27617\n\n\/\/ delete all employees\n\/\/ HTTP delete\nhttp:\/\/localhost:3000\/employees\/\n<\/pre>\n<p>That is all for this tutorial and I hope the article served you with whatever you were looking for. Happy Learning and do not forget to share!<\/p>\n<h2>6. Summary<\/h2>\n<p>In this tutorial, we learned how to create a MongoDB on Docker and create simple Node.js RESTful APIs with an Express web server application to perform the CRUD operations. You can download the source code and the postman collection from the <a href=\"#projectDownload\">Downloads<\/a> section.<\/p>\n<h2><a name=\"projectDownload\"><\/a>7. Download the Project<\/h2>\n<p>This was a tutorial to create a CRUD application in Node.js with MongoDB.<\/p>\n<div class=\"download\"><strong>Download<\/strong><br \/>You can download the full source code of this example here: <a href=\"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2021\/07\/Node.js-and-MongoDB-Tutorial.zip\"><strong>Node.js and MongoDB Tutorial<\/strong><\/a><\/div>\n","protected":false},"excerpt":{"rendered":"<p>Hello. In this tutorial, we will create a simple node.js application and perform the CRUD operations with the MongoDB. The node.js framework is commonly used to create server-based applications which are further used to show the contents to the users.\u00a0 1. Introduction Let us first understand that what is Mongo database and set up Node.js. &hellip;<\/p>\n","protected":false},"author":26931,"featured_media":20900,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1879],"tags":[513,991,112,668,741,1708,1978],"class_list":["post-110894","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-javascript","tag-crud","tag-express-js","tag-mongodb","tag-mongoose","tag-node-js","tag-rest-api","tag-restful-services"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.5 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>Node.js and MongoDB Tutorial - Java Code Geeks<\/title>\n<meta name=\"description\" content=\"Hello. In this tutorial, we will create a simple node.js application and perform the CRUD operations with the MongoDB. The node.js framework is commonly\" \/>\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.javacodegeeks.com\/node-js-and-mongodb-tutorial.html\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Node.js and MongoDB Tutorial - Java Code Geeks\" \/>\n<meta property=\"og:description\" content=\"Hello. In this tutorial, we will create a simple node.js application and perform the CRUD operations with the MongoDB. The node.js framework is commonly\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.javacodegeeks.com\/node-js-and-mongodb-tutorial.html\" \/>\n<meta property=\"og:site_name\" content=\"Java Code Geeks\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/javacodegeeks\" \/>\n<meta property=\"article:published_time\" content=\"2021-07-21T04:00:00+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2014\/01\/javascript-logo.jpg\" \/>\n\t<meta property=\"og:image:width\" content=\"150\" \/>\n\t<meta property=\"og:image:height\" content=\"150\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/jpeg\" \/>\n<meta name=\"author\" content=\"Yatin Batra\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@javacodegeeks\" \/>\n<meta name=\"twitter:site\" content=\"@javacodegeeks\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Yatin Batra\" \/>\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.javacodegeeks.com\\\/node-js-and-mongodb-tutorial.html#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/node-js-and-mongodb-tutorial.html\"},\"author\":{\"name\":\"Yatin Batra\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#\\\/schema\\\/person\\\/cda31a4c1965373fed40c8907dc09b8d\"},\"headline\":\"Node.js and MongoDB Tutorial\",\"datePublished\":\"2021-07-21T04:00:00+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/node-js-and-mongodb-tutorial.html\"},\"wordCount\":766,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#organization\"},\"image\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/node-js-and-mongodb-tutorial.html#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/www.javacodegeeks.com\\\/wp-content\\\/uploads\\\/2014\\\/01\\\/javascript-logo.jpg\",\"keywords\":[\"CRUD\",\"Express.js\",\"MongoDB\",\"Mongoose\",\"Node.js\",\"REST API\",\"RESTful services\"],\"articleSection\":[\"JavaScript\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\\\/\\\/www.javacodegeeks.com\\\/node-js-and-mongodb-tutorial.html#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/node-js-and-mongodb-tutorial.html\",\"url\":\"https:\\\/\\\/www.javacodegeeks.com\\\/node-js-and-mongodb-tutorial.html\",\"name\":\"Node.js and MongoDB Tutorial - Java Code Geeks\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/node-js-and-mongodb-tutorial.html#primaryimage\"},\"image\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/node-js-and-mongodb-tutorial.html#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/www.javacodegeeks.com\\\/wp-content\\\/uploads\\\/2014\\\/01\\\/javascript-logo.jpg\",\"datePublished\":\"2021-07-21T04:00:00+00:00\",\"description\":\"Hello. In this tutorial, we will create a simple node.js application and perform the CRUD operations with the MongoDB. The node.js framework is commonly\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/node-js-and-mongodb-tutorial.html#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/www.javacodegeeks.com\\\/node-js-and-mongodb-tutorial.html\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/node-js-and-mongodb-tutorial.html#primaryimage\",\"url\":\"https:\\\/\\\/www.javacodegeeks.com\\\/wp-content\\\/uploads\\\/2014\\\/01\\\/javascript-logo.jpg\",\"contentUrl\":\"https:\\\/\\\/www.javacodegeeks.com\\\/wp-content\\\/uploads\\\/2014\\\/01\\\/javascript-logo.jpg\",\"width\":150,\"height\":150},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/node-js-and-mongodb-tutorial.html#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/www.javacodegeeks.com\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Web Development\",\"item\":\"https:\\\/\\\/www.javacodegeeks.com\\\/category\\\/web-development\"},{\"@type\":\"ListItem\",\"position\":3,\"name\":\"JavaScript\",\"item\":\"https:\\\/\\\/www.javacodegeeks.com\\\/category\\\/web-development\\\/javascript\"},{\"@type\":\"ListItem\",\"position\":4,\"name\":\"Node.js and MongoDB Tutorial\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#website\",\"url\":\"https:\\\/\\\/www.javacodegeeks.com\\\/\",\"name\":\"Java Code Geeks\",\"description\":\"Java Developers Resource Center\",\"publisher\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#organization\"},\"alternateName\":\"JCG\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/www.javacodegeeks.com\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#organization\",\"name\":\"Exelixis Media P.C.\",\"url\":\"https:\\\/\\\/www.javacodegeeks.com\\\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#\\\/schema\\\/logo\\\/image\\\/\",\"url\":\"https:\\\/\\\/www.javacodegeeks.com\\\/wp-content\\\/uploads\\\/2022\\\/06\\\/exelixis-logo.png\",\"contentUrl\":\"https:\\\/\\\/www.javacodegeeks.com\\\/wp-content\\\/uploads\\\/2022\\\/06\\\/exelixis-logo.png\",\"width\":864,\"height\":246,\"caption\":\"Exelixis Media P.C.\"},\"image\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#\\\/schema\\\/logo\\\/image\\\/\"},\"sameAs\":[\"https:\\\/\\\/www.facebook.com\\\/javacodegeeks\",\"https:\\\/\\\/x.com\\\/javacodegeeks\"]},{\"@type\":\"Person\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#\\\/schema\\\/person\\\/cda31a4c1965373fed40c8907dc09b8d\",\"name\":\"Yatin Batra\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/wp-content\\\/uploads\\\/2022\\\/12\\\/Yatin.batra_.jpg\",\"url\":\"https:\\\/\\\/www.javacodegeeks.com\\\/wp-content\\\/uploads\\\/2022\\\/12\\\/Yatin.batra_.jpg\",\"contentUrl\":\"https:\\\/\\\/www.javacodegeeks.com\\\/wp-content\\\/uploads\\\/2022\\\/12\\\/Yatin.batra_.jpg\",\"caption\":\"Yatin Batra\"},\"description\":\"An experience full-stack engineer well versed with Core Java, Spring\\\/Springboot, MVC, Security, AOP, Frontend (Angular &amp; React), and cloud technologies (such as AWS, GCP, Jenkins, Docker, K8).\",\"sameAs\":[\"https:\\\/\\\/www.javacodegeeks.com\"],\"url\":\"https:\\\/\\\/www.javacodegeeks.com\\\/author\\\/yatin-batra\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Node.js and MongoDB Tutorial - Java Code Geeks","description":"Hello. In this tutorial, we will create a simple node.js application and perform the CRUD operations with the MongoDB. The node.js framework is commonly","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.javacodegeeks.com\/node-js-and-mongodb-tutorial.html","og_locale":"en_US","og_type":"article","og_title":"Node.js and MongoDB Tutorial - Java Code Geeks","og_description":"Hello. In this tutorial, we will create a simple node.js application and perform the CRUD operations with the MongoDB. The node.js framework is commonly","og_url":"https:\/\/www.javacodegeeks.com\/node-js-and-mongodb-tutorial.html","og_site_name":"Java Code Geeks","article_publisher":"https:\/\/www.facebook.com\/javacodegeeks","article_published_time":"2021-07-21T04:00:00+00:00","og_image":[{"width":150,"height":150,"url":"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2014\/01\/javascript-logo.jpg","type":"image\/jpeg"}],"author":"Yatin Batra","twitter_card":"summary_large_image","twitter_creator":"@javacodegeeks","twitter_site":"@javacodegeeks","twitter_misc":{"Written by":"Yatin Batra","Est. reading time":"7 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/www.javacodegeeks.com\/node-js-and-mongodb-tutorial.html#article","isPartOf":{"@id":"https:\/\/www.javacodegeeks.com\/node-js-and-mongodb-tutorial.html"},"author":{"name":"Yatin Batra","@id":"https:\/\/www.javacodegeeks.com\/#\/schema\/person\/cda31a4c1965373fed40c8907dc09b8d"},"headline":"Node.js and MongoDB Tutorial","datePublished":"2021-07-21T04:00:00+00:00","mainEntityOfPage":{"@id":"https:\/\/www.javacodegeeks.com\/node-js-and-mongodb-tutorial.html"},"wordCount":766,"commentCount":0,"publisher":{"@id":"https:\/\/www.javacodegeeks.com\/#organization"},"image":{"@id":"https:\/\/www.javacodegeeks.com\/node-js-and-mongodb-tutorial.html#primaryimage"},"thumbnailUrl":"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2014\/01\/javascript-logo.jpg","keywords":["CRUD","Express.js","MongoDB","Mongoose","Node.js","REST API","RESTful services"],"articleSection":["JavaScript"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/www.javacodegeeks.com\/node-js-and-mongodb-tutorial.html#respond"]}]},{"@type":"WebPage","@id":"https:\/\/www.javacodegeeks.com\/node-js-and-mongodb-tutorial.html","url":"https:\/\/www.javacodegeeks.com\/node-js-and-mongodb-tutorial.html","name":"Node.js and MongoDB Tutorial - Java Code Geeks","isPartOf":{"@id":"https:\/\/www.javacodegeeks.com\/#website"},"primaryImageOfPage":{"@id":"https:\/\/www.javacodegeeks.com\/node-js-and-mongodb-tutorial.html#primaryimage"},"image":{"@id":"https:\/\/www.javacodegeeks.com\/node-js-and-mongodb-tutorial.html#primaryimage"},"thumbnailUrl":"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2014\/01\/javascript-logo.jpg","datePublished":"2021-07-21T04:00:00+00:00","description":"Hello. In this tutorial, we will create a simple node.js application and perform the CRUD operations with the MongoDB. The node.js framework is commonly","breadcrumb":{"@id":"https:\/\/www.javacodegeeks.com\/node-js-and-mongodb-tutorial.html#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.javacodegeeks.com\/node-js-and-mongodb-tutorial.html"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.javacodegeeks.com\/node-js-and-mongodb-tutorial.html#primaryimage","url":"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2014\/01\/javascript-logo.jpg","contentUrl":"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2014\/01\/javascript-logo.jpg","width":150,"height":150},{"@type":"BreadcrumbList","@id":"https:\/\/www.javacodegeeks.com\/node-js-and-mongodb-tutorial.html#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.javacodegeeks.com\/"},{"@type":"ListItem","position":2,"name":"Web Development","item":"https:\/\/www.javacodegeeks.com\/category\/web-development"},{"@type":"ListItem","position":3,"name":"JavaScript","item":"https:\/\/www.javacodegeeks.com\/category\/web-development\/javascript"},{"@type":"ListItem","position":4,"name":"Node.js and MongoDB Tutorial"}]},{"@type":"WebSite","@id":"https:\/\/www.javacodegeeks.com\/#website","url":"https:\/\/www.javacodegeeks.com\/","name":"Java Code Geeks","description":"Java Developers Resource Center","publisher":{"@id":"https:\/\/www.javacodegeeks.com\/#organization"},"alternateName":"JCG","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.javacodegeeks.com\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/www.javacodegeeks.com\/#organization","name":"Exelixis Media P.C.","url":"https:\/\/www.javacodegeeks.com\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.javacodegeeks.com\/#\/schema\/logo\/image\/","url":"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2022\/06\/exelixis-logo.png","contentUrl":"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2022\/06\/exelixis-logo.png","width":864,"height":246,"caption":"Exelixis Media P.C."},"image":{"@id":"https:\/\/www.javacodegeeks.com\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/javacodegeeks","https:\/\/x.com\/javacodegeeks"]},{"@type":"Person","@id":"https:\/\/www.javacodegeeks.com\/#\/schema\/person\/cda31a4c1965373fed40c8907dc09b8d","name":"Yatin Batra","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2022\/12\/Yatin.batra_.jpg","url":"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2022\/12\/Yatin.batra_.jpg","contentUrl":"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2022\/12\/Yatin.batra_.jpg","caption":"Yatin Batra"},"description":"An experience full-stack engineer well versed with Core Java, Spring\/Springboot, MVC, Security, AOP, Frontend (Angular &amp; React), and cloud technologies (such as AWS, GCP, Jenkins, Docker, K8).","sameAs":["https:\/\/www.javacodegeeks.com"],"url":"https:\/\/www.javacodegeeks.com\/author\/yatin-batra"}]}},"_links":{"self":[{"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/posts\/110894","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/users\/26931"}],"replies":[{"embeddable":true,"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/comments?post=110894"}],"version-history":[{"count":0,"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/posts\/110894\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/media\/20900"}],"wp:attachment":[{"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/media?parent=110894"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/categories?post=110894"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/tags?post=110894"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}