Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
291 views
in Technique[技术] by (71.8m points)

Spring Boot MongoDB data persistence issue

I am new to Spring Boot and MongoDB.

I was following a tutorial to insert and get documents in a mongoDB collection when using Spring Boot. When I make post and get requests, I am able to add and receive the data, however these changes (insertion of documents) doesn't reflect in the database when I check it through the MongoDB Compass application. Moreover the existing data in the collection cannot be fetched (fetchById() returns null).

Model for Issues:

package com.demo.model;

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

@Document(collection="issues")
public class Issues {
    
    @Id
    private String description;
    private int severity;
    private String assignee;
    
    public String getDescription() {
        return description;
    }
    public void setDescription(String description) {
        this.description = description;
    }
    public int getSeverity() {
        return severity;
    }
    public void setSeverity(int severity) {
        this.severity = severity;
    }
    public String getAssignee() {
        return assignee;
    }
    public void setAssignee(String assignee) {
        this.assignee = assignee;
    }
    
}

IssuesRepository:

package com.demo.repository;

import org.springframework.data.mongodb.repository.MongoRepository;
import org.springframework.stereotype.Repository;

import com.demo.model.Issues;

@Repository
public interface IssuesRepository extends MongoRepository<Issues, String> {

}

application.properties:

spring.data.mongodb.host=localhost
spring.data.mongodb.port=27017
spring.data.mongodb.database=issues

MongoDB Compass screenshot displaying collection

question from:https://stackoverflow.com/questions/66060726/spring-boot-mongodb-data-persistence-issue

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...