Code Monkey home page Code Monkey logo

mongodb_springboot's Introduction

MongoDB_SpringBoot

Interacting with MongoDB local and MongoDB Atlas cloud using Spring Boot Framework

Preqequisites

  1. Download and install MongoDB in local machine
  2. Add environment variable for MongoDB bin folder
  3. Open command prompt and type mongod to start mongodb server. MongoDB server runs on port 27017
  4. By default mongod runs as a background service on windows
  5. Open another command prompt terminal and run mongo to start mongo shell client. It automatically connects to mongodb server on port 27017

#Cluster Mode - Replication

#create 3 mongo server cluster with 1 primary and 2 secondary

mongod --port 27017 --dbpath "C:\Users\keeth\Desktop\Dinesh-Spring-boot\mongoDB\mongo-replication\data0" --replSet "rs0" --bind_ip localhost
mongod --port 27018 --dbpath "C:\Users\keeth\Desktop\Dinesh-Spring-boot\mongoDB\mongo-replication\data1" --replSet "rs0" --bind_ip localhost
mongod --port 27019 --dbpath "C:\Users\keeth\Desktop\Dinesh-Spring-boot\mongoDB\mongo-replication\data2" --replSet "rs0" --bind_ip localhost

mongo shell client #this wil initiate the replica set and add 27017 to the replica set rs.initiate() #Add the other 2 nodes in the replica set rs.add("localhost:27018") rs.add("localhost:27019")

#Mongo DB Atlas

  1. Create a MongoDB Atlas cluster in free tier
  2. Obtain the cluster endpoint for shell and Java application
  3. Use the cluster endpoint to connect to the MongoDB Atlas Cluster either from shell or the application

#Steps

  1. Download the Spring Data MongoDB for the Spring Boot application to talk to the MongoDB database
  2. Use the MongoDB localhost credentials to connect to MongoDB local
  3. Use MongoDB Atlas cluster endpoint to access MongoDB in the cloud
  4. Run the java program
  5. Verify the data either from Mongo Atlas console or from the shell
  6. Use Spring boot mongotemplate to have more granual access to the data
  7. MongoRepository provides high level CRUD operations and we cannot control the data in more granular by queries
  8. MongoTemplate has query functionality which lets us to access only the data we require instead of loading all the unnecessary data

Mongo DB Architecture

MongoDB Architecture

MongoDB Atlas Console

MongoDB Atlas

MongoDB Stitch

MongoDB Stitch

mongodb_springboot's People

Contributors

dineschandgr avatar keethugithub avatar

Watchers

 avatar  avatar

Forkers

daskoushik

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.