Skip to content

sovanmukherjee/springboot-mongodb-rest

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Getting Started

Reference Documentation

For further reference, please consider the following sections:

Guides

The following guides illustrate how to use some features concretely:

Additional Links

These additional references should also help you:

Install MongoDB locally on Mac

  1. Download MongoDB MongoDB Community Server image

  2. Setup MONGO_HOME environment variable image

  3. Check mongo version in command prompt/Terminal

mongo --version image

  1. Setting Database Server : Create a folder or directory which will store all the data processed by the mongod

mongod --dbpath /Users/sovanmukherjee/dev/Software/mongodb image

  1. Install mongoDb Compass to see collection and data image

After installation open MongoDB Campass image

  1. Click on Fill in connection fields image

  2. Provide all required information and click on connect image

image

  1. You can create database and Collection manually

image

image

  1. Check all databases through command prompt

mongo

show dbs image

  1. Use database with database name

Syntax: use <DB_NAME> image

  1. Create index

Syntax: db.COLLECTION_NAME.createIndex({KEY:1})

db.student.createIndex({"crTime": 1})

  1. View index

Syntax: db.COLLECTION_NAME.getIndexes()

db.student.getIndexes()

image

Add TTL on mongoDB

  1. create TTL Index

Syntax: db.COLLECTION_NAME.createIndex({"KEY": 1},{expireAfter: "3600s"})

-OR -

db.COLLECTION_NAME.createIndex( { "KEY": 1 }, { expireAfterSeconds: 3600 } )

Example: db.student.createIndex({"crTime": 1},{expireAfter: "3600s"})

image

Run Application

Local Swagger UI: http://localhost:8080/swagger-ui/index.html image

Save Student

image

You can check data in Compass

image

image

Get Students By className

Request payload image Response payload

{
  "content": [
    {
      "id": "1971a4ab-5226-4f81-b3fc-ffde69aa8277",
      "rollNumber": 1,
      "contact": {
        "emailId": "[email protected]",
        "mobile": "9999999999"
      },
      "vsningFlds": {
        "createdBy": "abc",
        "crTime": "2022-09-24T22:34:11.826"
      }
    },
    {
      "id": "cdb5d2e7-36ee-40c8-bc66-6eefa5b7d503",
      "rollNumber": 2,
      "contact": {
        "emailId": "[email protected]",
        "mobile": "9999999999"
      },
      "vsningFlds": {
        "createdBy": "abc",
        "crTime": "2022-09-24T22:37:47.863"
      }
    },
    {
      "id": "a3fc979f-3835-4e19-a374-8ca849711144",
      "rollNumber": 3,
      "contact": {
        "emailId": "[email protected]",
        "mobile": "9999999999"
      },
      "vsningFlds": {
        "createdBy": "abc",
        "crTime": "2022-09-24T22:38:19.39"
      }
    },
    {
      "id": "db30ce97-d29b-437f-b754-15354ef8b861",
      "rollNumber": 4,
      "contact": {
        "emailId": "[email protected]",
        "mobile": "9999999999"
      },
      "vsningFlds": {
        "createdBy": "abc",
        "crTime": "2022-09-24T22:39:24.644"
      }
    },
    {
      "id": "c71bc980-1476-474f-a709-43bd1a28f20a",
      "rollNumber": 5,
      "contact": {
        "emailId": "[email protected]",
        "mobile": "9999999999"
      },
      "vsningFlds": {
        "createdBy": "abc",
        "crTime": "2022-09-24T22:39:50.437"
      }
    }
  ],
  "pageable": {
    "sort": {
      "empty": false,
      "sorted": true,
      "unsorted": false
    },
    "offset": 0,
    "pageNumber": 0,
    "pageSize": 10,
    "paged": true,
    "unpaged": false
  },
  "last": true,
  "totalPages": 1,
  "totalElements": 5,
  "first": true,
  "size": 10,
  "number": 0,
  "sort": {
    "empty": false,
    "sorted": true,
    "unsorted": false
  },
  "numberOfElements": 5,
  "empty": false
}

Releases

No releases published

Packages

No packages published

Languages