SlideShare a Scribd company logo
1 of 14
Freelancer Remedies
Freelancer Remedies
Myself Manoj Mohanan
Freelance Web Developer
LinkedIn: https://in.linkedin.com/in/manojmohanan1988
Freelancer Remedies
Thank you for coming...
Freelancer Remedies
How to use multiple mongodb database in a nodejs
express mongodb application
Freelancer Remedies
How to use multiple mongodb databases in a nodejs express mongodb application
Presentation content
1. Describe project
2. Live Demo
3. Explain code
4. Share git repo link
Freelancer Remedies
How to use multiple mongodb databases in a nodejs express mongodb application
1. Describe project
Single express node js application need to serve two hosts.
Routes and models are the same but the mongodb database are different.
Freelancer Remedies
How to use multiple mongodb databases in a nodejs express mongodb application
1. Describe project
Single express node js application need to serve two hosts.Routes and
models are the same but the mongodb database are different.
For example:
Node Js
Express Js
Mongoose
DB
DB
Host 1
Host 2
Application
mongodb://localhost/localhost-dev
mongodb://localhost/physical-dev-127
http://localhost:3000
http://127.0.0.1:3000
Routes
/ -- showing user json data from the database
/random -- insert random strings to user table
Available routes
1. http://localhost:3000/
2. http://locahost:3000/random
Available routes
1. http://127.0.0.1:3000/
2. http://127.0.0.1::3000/random
Master Server
Hosts pointed to the master server
Freelancer Remedies
How to use multiple mongodb databases in a nodejs express mongodb application
Demo
Freelancer Remedies
How to use multiple mongodb databases in a nodejs express mongodb application
Demo
Freelancer Remedies
How to use multiple mongodb databases in a nodejs express mongodb application
Explain Code
Freelancer Remedies
How to use multiple mongodb databases in a nodejs express mongodb application
Code 1:
Routes
Creating new user model
related to the current requested
hostname
Using user model
related to the current requested
hostname
Route definitions and Starting the server code
Freelancer Remedies
How to use multiple mongodb databases in a nodejs express mongodb application
Code 2:
User schema
Here is the middleware code
for saving the mongodb instance by host
name to the global stack
Defining the global Stack
Freelancer Remedies
How to use multiple mongodb databases in a nodejs express mongodb application
Git Repository:
https://github.com/phpremedy/Simple-Hack-Use-multipple-mongodb-databases-in-a-nodejs-express-mongodb-application
Freelancer Remedies
The End
Thank you.

More Related Content

What's hot

What's hot (12)

Web with Nodejs
Web with NodejsWeb with Nodejs
Web with Nodejs
 
Introduction to Javascript in Magento 2 | Colorado Magento Meetup
Introduction to Javascript in Magento 2 | Colorado Magento MeetupIntroduction to Javascript in Magento 2 | Colorado Magento Meetup
Introduction to Javascript in Magento 2 | Colorado Magento Meetup
 
Node js Modules and Event Emitters
Node js Modules and Event EmittersNode js Modules and Event Emitters
Node js Modules and Event Emitters
 
Getting Started with MongoDB and Node.js
Getting Started with MongoDB and Node.jsGetting Started with MongoDB and Node.js
Getting Started with MongoDB and Node.js
 
Introduction to node
Introduction to nodeIntroduction to node
Introduction to node
 
Node.js and Ruby
Node.js and RubyNode.js and Ruby
Node.js and Ruby
 
Zero to Hipster with the M.I.K.E. Stack
Zero to Hipster with the M.I.K.E. StackZero to Hipster with the M.I.K.E. Stack
Zero to Hipster with the M.I.K.E. Stack
 
Cscript exe
Cscript exeCscript exe
Cscript exe
 
Flask jwt authentication tutorial
Flask jwt authentication tutorialFlask jwt authentication tutorial
Flask jwt authentication tutorial
 
Create a RESTful API with NodeJS, Express and MongoDB
Create a RESTful API with NodeJS, Express and MongoDBCreate a RESTful API with NodeJS, Express and MongoDB
Create a RESTful API with NodeJS, Express and MongoDB
 
PHP client - Mongo db User Group Pune
PHP client - Mongo db User Group PunePHP client - Mongo db User Group Pune
PHP client - Mongo db User Group Pune
 
Web workers
Web workers Web workers
Web workers
 

Similar to Simple hack: use multiple mongodb databases in a nodejs express mongodb application

Beginning MEAN Stack
Beginning MEAN StackBeginning MEAN Stack
Beginning MEAN Stack
Rob Davarnia
 
A flexible plugin like data layer - decouple your -_application logic from yo...
A flexible plugin like data layer - decouple your -_application logic from yo...A flexible plugin like data layer - decouple your -_application logic from yo...
A flexible plugin like data layer - decouple your -_application logic from yo...
MongoDB
 
Node Js Non-blocking or asynchronous Blocking or synchronous.pdf
Node Js Non-blocking or asynchronous  Blocking or synchronous.pdfNode Js Non-blocking or asynchronous  Blocking or synchronous.pdf
Node Js Non-blocking or asynchronous Blocking or synchronous.pdf
DarshanaMallick
 
MongoDB at Gilt Groupe
MongoDB at Gilt GroupeMongoDB at Gilt Groupe
MongoDB at Gilt Groupe
MongoDB
 

Similar to Simple hack: use multiple mongodb databases in a nodejs express mongodb application (20)

How do you connect your mongo db database with node.js
How do you connect your mongo db database with node.js How do you connect your mongo db database with node.js
How do you connect your mongo db database with node.js
 
Basic API Creation with Node.JS
Basic API Creation with Node.JSBasic API Creation with Node.JS
Basic API Creation with Node.JS
 
Node Js, AngularJs and Express Js Tutorial
Node Js, AngularJs and Express Js TutorialNode Js, AngularJs and Express Js Tutorial
Node Js, AngularJs and Express Js Tutorial
 
Beginning MEAN Stack
Beginning MEAN StackBeginning MEAN Stack
Beginning MEAN Stack
 
Building Applications With the MEAN Stack
Building Applications With the MEAN StackBuilding Applications With the MEAN Stack
Building Applications With the MEAN Stack
 
Mdb dn 2016_07_elastic_search
Mdb dn 2016_07_elastic_searchMdb dn 2016_07_elastic_search
Mdb dn 2016_07_elastic_search
 
All You Need to Know About Using Node.pdf
All You Need to Know About Using Node.pdfAll You Need to Know About Using Node.pdf
All You Need to Know About Using Node.pdf
 
A flexible plugin like data layer - decouple your -_application logic from yo...
A flexible plugin like data layer - decouple your -_application logic from yo...A flexible plugin like data layer - decouple your -_application logic from yo...
A flexible plugin like data layer - decouple your -_application logic from yo...
 
Node Js Non-blocking or asynchronous Blocking or synchronous.pdf
Node Js Non-blocking or asynchronous  Blocking or synchronous.pdfNode Js Non-blocking or asynchronous  Blocking or synchronous.pdf
Node Js Non-blocking or asynchronous Blocking or synchronous.pdf
 
Complete MVC on NodeJS
Complete MVC on NodeJSComplete MVC on NodeJS
Complete MVC on NodeJS
 
Scaling MongoDB with Docker and cgroups
Scaling MongoDB with Docker and cgroupsScaling MongoDB with Docker and cgroups
Scaling MongoDB with Docker and cgroups
 
MongoDB World 2016: Scaling MongoDB with Docker and cGroups
MongoDB World 2016: Scaling MongoDB with Docker and cGroupsMongoDB World 2016: Scaling MongoDB with Docker and cGroups
MongoDB World 2016: Scaling MongoDB with Docker and cGroups
 
Node js
Node jsNode js
Node js
 
MongoDB at Gilt Groupe
MongoDB at Gilt GroupeMongoDB at Gilt Groupe
MongoDB at Gilt Groupe
 
Meteor Introduction
Meteor IntroductionMeteor Introduction
Meteor Introduction
 
node.js.pptx
node.js.pptxnode.js.pptx
node.js.pptx
 
Node js installation steps.pptx slide share ppts
Node js installation steps.pptx slide share pptsNode js installation steps.pptx slide share ppts
Node js installation steps.pptx slide share ppts
 
node_js.pptx
node_js.pptxnode_js.pptx
node_js.pptx
 
Node.Js vs PHP Which One Should You Choose.pdf
Node.Js vs PHP Which One Should You Choose.pdfNode.Js vs PHP Which One Should You Choose.pdf
Node.Js vs PHP Which One Should You Choose.pdf
 
Node JS
Node JSNode JS
Node JS
 

Recently uploaded

Recently uploaded (20)

Lessons Learned from Building a Serverless Notifications System.pdf
Lessons Learned from Building a Serverless Notifications System.pdfLessons Learned from Building a Serverless Notifications System.pdf
Lessons Learned from Building a Serverless Notifications System.pdf
 
Abortion Pill Prices Germiston ](+27832195400*)[ 🏥 Women's Abortion Clinic in...
Abortion Pill Prices Germiston ](+27832195400*)[ 🏥 Women's Abortion Clinic in...Abortion Pill Prices Germiston ](+27832195400*)[ 🏥 Women's Abortion Clinic in...
Abortion Pill Prices Germiston ](+27832195400*)[ 🏥 Women's Abortion Clinic in...
 
Abortion Clinic In Springs ](+27832195400*)[ 🏥 Safe Abortion Pills in Springs...
Abortion Clinic In Springs ](+27832195400*)[ 🏥 Safe Abortion Pills in Springs...Abortion Clinic In Springs ](+27832195400*)[ 🏥 Safe Abortion Pills in Springs...
Abortion Clinic In Springs ](+27832195400*)[ 🏥 Safe Abortion Pills in Springs...
 
architecting-ai-in-the-enterprise-apis-and-applications.pdf
architecting-ai-in-the-enterprise-apis-and-applications.pdfarchitecting-ai-in-the-enterprise-apis-and-applications.pdf
architecting-ai-in-the-enterprise-apis-and-applications.pdf
 
Rapidoform for Modern Form Building and Insights
Rapidoform for Modern Form Building and InsightsRapidoform for Modern Form Building and Insights
Rapidoform for Modern Form Building and Insights
 
A Deep Dive into Secure Product Development Frameworks.pdf
A Deep Dive into Secure Product Development Frameworks.pdfA Deep Dive into Secure Product Development Frameworks.pdf
A Deep Dive into Secure Product Development Frameworks.pdf
 
OpenChain Webinar: AboutCode and Beyond - End-to-End SCA
OpenChain Webinar: AboutCode and Beyond - End-to-End SCAOpenChain Webinar: AboutCode and Beyond - End-to-End SCA
OpenChain Webinar: AboutCode and Beyond - End-to-End SCA
 
Abortion Pill Prices Jane Furse ](+27832195400*)[ 🏥 Women's Abortion Clinic i...
Abortion Pill Prices Jane Furse ](+27832195400*)[ 🏥 Women's Abortion Clinic i...Abortion Pill Prices Jane Furse ](+27832195400*)[ 🏥 Women's Abortion Clinic i...
Abortion Pill Prices Jane Furse ](+27832195400*)[ 🏥 Women's Abortion Clinic i...
 
Community is Just as Important as Code by Andrea Goulet
Community is Just as Important as Code by Andrea GouletCommunity is Just as Important as Code by Andrea Goulet
Community is Just as Important as Code by Andrea Goulet
 
Workshop: Enabling GenAI Breakthroughs with Knowledge Graphs - GraphSummit Milan
Workshop: Enabling GenAI Breakthroughs with Knowledge Graphs - GraphSummit MilanWorkshop: Enabling GenAI Breakthroughs with Knowledge Graphs - GraphSummit Milan
Workshop: Enabling GenAI Breakthroughs with Knowledge Graphs - GraphSummit Milan
 
Abortion Clinic In Johannesburg ](+27832195400*)[ 🏥 Safe Abortion Pills in Jo...
Abortion Clinic In Johannesburg ](+27832195400*)[ 🏥 Safe Abortion Pills in Jo...Abortion Clinic In Johannesburg ](+27832195400*)[ 🏥 Safe Abortion Pills in Jo...
Abortion Clinic In Johannesburg ](+27832195400*)[ 🏥 Safe Abortion Pills in Jo...
 
Test Automation Design Patterns_ A Comprehensive Guide.pdf
Test Automation Design Patterns_ A Comprehensive Guide.pdfTest Automation Design Patterns_ A Comprehensive Guide.pdf
Test Automation Design Patterns_ A Comprehensive Guide.pdf
 
CERVED e Neo4j su una nuvola, migrazione ed evoluzione di un grafo mission cr...
CERVED e Neo4j su una nuvola, migrazione ed evoluzione di un grafo mission cr...CERVED e Neo4j su una nuvola, migrazione ed evoluzione di un grafo mission cr...
CERVED e Neo4j su una nuvola, migrazione ed evoluzione di un grafo mission cr...
 
[GeeCON2024] How I learned to stop worrying and love the dark silicon apocalypse
[GeeCON2024] How I learned to stop worrying and love the dark silicon apocalypse[GeeCON2024] How I learned to stop worrying and love the dark silicon apocalypse
[GeeCON2024] How I learned to stop worrying and love the dark silicon apocalypse
 
Microsoft365_Dev_Security_2024_05_16.pdf
Microsoft365_Dev_Security_2024_05_16.pdfMicrosoft365_Dev_Security_2024_05_16.pdf
Microsoft365_Dev_Security_2024_05_16.pdf
 
Effective Strategies for Wix's Scaling challenges - GeeCon
Effective Strategies for Wix's Scaling challenges - GeeConEffective Strategies for Wix's Scaling challenges - GeeCon
Effective Strategies for Wix's Scaling challenges - GeeCon
 
Your Ultimate Web Studio for Streaming Anywhere | Evmux
Your Ultimate Web Studio for Streaming Anywhere | EvmuxYour Ultimate Web Studio for Streaming Anywhere | Evmux
Your Ultimate Web Studio for Streaming Anywhere | Evmux
 
Prompt Engineering - an Art, a Science, or your next Job Title?
Prompt Engineering - an Art, a Science, or your next Job Title?Prompt Engineering - an Art, a Science, or your next Job Title?
Prompt Engineering - an Art, a Science, or your next Job Title?
 
Encryption Recap: A Refresher on Key Concepts
Encryption Recap: A Refresher on Key ConceptsEncryption Recap: A Refresher on Key Concepts
Encryption Recap: A Refresher on Key Concepts
 
BusinessGPT - Security and Governance for Generative AI
BusinessGPT  - Security and Governance for Generative AIBusinessGPT  - Security and Governance for Generative AI
BusinessGPT - Security and Governance for Generative AI
 

Simple hack: use multiple mongodb databases in a nodejs express mongodb application

  • 2. Freelancer Remedies Myself Manoj Mohanan Freelance Web Developer LinkedIn: https://in.linkedin.com/in/manojmohanan1988
  • 4. Freelancer Remedies How to use multiple mongodb database in a nodejs express mongodb application
  • 5. Freelancer Remedies How to use multiple mongodb databases in a nodejs express mongodb application Presentation content 1. Describe project 2. Live Demo 3. Explain code 4. Share git repo link
  • 6. Freelancer Remedies How to use multiple mongodb databases in a nodejs express mongodb application 1. Describe project Single express node js application need to serve two hosts. Routes and models are the same but the mongodb database are different.
  • 7. Freelancer Remedies How to use multiple mongodb databases in a nodejs express mongodb application 1. Describe project Single express node js application need to serve two hosts.Routes and models are the same but the mongodb database are different. For example: Node Js Express Js Mongoose DB DB Host 1 Host 2 Application mongodb://localhost/localhost-dev mongodb://localhost/physical-dev-127 http://localhost:3000 http://127.0.0.1:3000 Routes / -- showing user json data from the database /random -- insert random strings to user table Available routes 1. http://localhost:3000/ 2. http://locahost:3000/random Available routes 1. http://127.0.0.1:3000/ 2. http://127.0.0.1::3000/random Master Server Hosts pointed to the master server
  • 8. Freelancer Remedies How to use multiple mongodb databases in a nodejs express mongodb application Demo
  • 9. Freelancer Remedies How to use multiple mongodb databases in a nodejs express mongodb application Demo
  • 10. Freelancer Remedies How to use multiple mongodb databases in a nodejs express mongodb application Explain Code
  • 11. Freelancer Remedies How to use multiple mongodb databases in a nodejs express mongodb application Code 1: Routes Creating new user model related to the current requested hostname Using user model related to the current requested hostname Route definitions and Starting the server code
  • 12. Freelancer Remedies How to use multiple mongodb databases in a nodejs express mongodb application Code 2: User schema Here is the middleware code for saving the mongodb instance by host name to the global stack Defining the global Stack
  • 13. Freelancer Remedies How to use multiple mongodb databases in a nodejs express mongodb application Git Repository: https://github.com/phpremedy/Simple-Hack-Use-multipple-mongodb-databases-in-a-nodejs-express-mongodb-application