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 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…