Springboot mongodb 연동

2020. 9. 20. 16:08 from Development Log

docker에 mongodb를 실행

 - mongodb.yml

version: '3.4'

services:
  mongo:
    image: mongo
    restart: always
    ports:
      - 27017:27017
    environment:
      MONGO_INITDB_ROOT_USERNAME: root
      MONGO_INITDB_ROOT_PASSWORD: root
    volumes:
      - [host_volume_path]:/data/db

  mongo-express:
    image: mongo-express
    restart: always
    ports:
      - 8081:8081
    environment:
      ME_CONFIG_MONGODB_ADMINUSERNAME: root
      ME_CONFIG_MONGODB_ADMINPASSWORD: root
% docker-compose -f mongodb.yml up -d

 

springboot project

 - pom.xml

<dependency>
	<groupId>org.springframework.boot</groupId>
	<artifactId>spring-boot-starter-data-mongodb</artifactId>
</dependency>

 

 - Images.java

import java.util.HashMap;

import org.springframework.data.annotation.Id;
import org.springframework.data.mongodb.core.mapping.Document;

import lombok.Data;

@Data
@Document(collection = "images")
public class Images {
	@Id
	private String id;
	private String filename;
	private String originfilename;
	private HashMap<Object, HashMap<Object, Object>> metadata;
}

 

Service  구현

@Autowired
private MongoTemplate mongoTemplate;
Images images = new Images();
images.setFilename(uuidFileName);
images.setOriginfilename(fileName);
images.setMetadata(metadata);
mongoTemplate.insert(images);

 

Data 확인

{
    _id: ObjectId('5f66fabd5b489c6f988327f7'),
    filename: 'd3bde09d-621e-41db-835d-6df13a6c3f54.JPG',
    originfilename: '2018_04_04_0258.JPG',
    metadata: {
        'Exif Thumbnail': {
            'Resolution Unit': 'Inch',
            'Thumbnail Length': '10567 bytes',
            Compression: 'JPEG (old-style)',
            'Thumbnail Offset': '7620 bytes',
            'X Resolution': '350 dots per inch',
            'Y Resolution': '350 dots per inch'
        },
        Huffman: {
            'Number of Tables': '4 Huffman tables'
        },
        'File Type': {
            'Detected File Type Long Name': 'Joint Photographic Experts Group',
            'Detected File Type Name': 'JPEG',
            'Detected MIME Type': 'image/jpeg',
            'Expected File Name Extension': 'jpg'
        },
        JPEG: {
            'Component 3': 'Cr component: Quantization table 1, Sampling factors 1 horiz/1 vert',
            'Compression Type': 'Baseline',
            'Data Precision': '8 bits',
            'Number of Components': '3',
            'Component 2': 'Cb component: Quantization table 1, Sampling factors 1 horiz/1 vert',
            'Component 1': 'Y component: Quantization table 0, Sampling factors 2 horiz/1 vert',
            'Image Height': '4480 pixels',
            'Image Width': '6720 pixels'
        },
        Interoperability: {
            'Interoperability Version': '1.00',
            'Related Image Width': '6720',
            'Related Image Height': '4480',
            'Interoperability Index': 'Recommended Exif Interoperability Rules (ExifR98)'
        }
    },
    _class: 'com.nubiform.mongo.document.Images'
}

'Development Log' 카테고리의 다른 글

mongodb 설정  (0) 2020.09.23
sample-axios  (0) 2020.09.21
ngrok 설정  (0) 2020.09.18
React 01  (0) 2020.09.11
Springboot Docker Image  (0) 2020.09.06
Posted by NuBiFoRM :