mongod --version
입력💻 참고 사이트 : MongoDB 다운로드 방법 참고
💻 참고 코드 : springboot-webflux-mongo-chatapp
dependencies {
implementation 'org.springframework.boot:spring-boot-starter-data-mongodb-reactive'
implementation 'org.springframework.boot:spring-boot-starter-webflux'
compileOnly 'org.projectlombok:lombok'
developmentOnly 'org.springframework.boot:spring-boot-devtools'
annotationProcessor 'org.projectlombok:lombok'
testImplementation 'org.springframework.boot:spring-boot-starter-test'
testImplementation 'io.projectreactor:reactor-test'
}
spring:
data:
mongodb:
host: localhost
port: 27017 # MongoDB 기본 포트
database: chatdb # 해당 프로젝트 MongoDB 데이터베이스 이름
package com.ll.mongoChat;
import lombok.Data;
import org.springframework.data.annotation.Id;
import org.springframework.data.mongodb.core.mapping.Document;
import java.time.LocalDateTime;
@Data
@Document(collection = "chat")
public class Chat {
@Id
private String id;
private String msg;
private String sender; // 보내는 사람
private String receiver; // 받는 사람 (귓속말)
private Integer roomNum; // 방 번호
private LocalDateTime createdAt;
}
오류 내용
[8a95178a-2] There was an unexpected error (type=Internal Server Error, status=500).
Command failed with error 2 (BadValue): 'Field 'locale' is invalid in: { locale: "chat" }' on server localhost:27017. The full response is {"ok": 0.0, "errmsg": "Field 'locale' is invalid in: { locale: \"chat\" }", "code": 2, "codeName": "BadValue"}
org.springframework.data.mongodb.UncategorizedMongoDbException: Command failed with error 2 (BadValue): 'Field 'locale' is invalid in: { locale: "chat" }' on server localhost:27017. The full response is {"ok": 0.0, "errmsg": "Field 'locale' is invalid in: { locale: \"chat\" }", "code": 2, "codeName": "BadValue"}
at org.springframework.data.mongodb.core.MongoExceptionTranslator.translateExceptionIfPossible(MongoExceptionTranslator.java:140)
Suppressed: The stacktrace has been enhanced by Reactor, refer to additional information below:
Error has been observed at the following site(s):
*__checkpoint ⇢ Handler com.ll.mongoChat.ChatController#findByRoomNum(Integer) [DispatcherHandler]
*__checkpoint ⇢ HTTP GET "/chat/roomNum/1" [ExceptionHandlingWebHandler]
오류 내용
2023-08-16T16:33:25.545+09:00 ERROR 10340 --- [ntLoopGroup-3-3] a.w.r.e.AbstractErrorWebExceptionHandler : [2cad4529-1] 500 Server Error for HTTP GET "/chat/roomNum/1"
org.springframework.data.mongodb.UncategorizedMongoDbException: Command failed with error 2 (BadValue): 'error processing query: ns=chatdb.chat batchSize=2Tree: roomNum $eq 1
Sort: {}
Proj: {}
tailable cursor requested on non capped collection' on server localhost:27017. The full response is {"ok": 0.0, "errmsg": "error processing query: ns=chatdb.chat batchSize=2Tree: roomNum $eq 1\nSort: {}\nProj: {}\n tailable cursor requested on non capped collection", "code": 2, "codeName": "BadValue"}
at org.springframework.data.mongodb.core.MongoExceptionTranslator.translateExceptionIfPossible(MongoExceptionTranslator.java:140) ~[spring-data-mongodb-4.1.2.jar:4.1.2]
Suppressed: reactor.core.publisher.FluxOnAssembly$OnAssemblyException:
Error has been observed at the following site(s):
*__checkpoint ⇢ Handler com.ll.mongoChat.ChatController#findByRoomNum(Integer) [DispatcherHandler]
*__checkpoint ⇢ HTTP GET "/chat/roomNum/1" [ExceptionHandlingWebHandler]
tailable cursor가 capped collection이 아닌 컬렉션에서 요청되었음을 의미
📌 해결 방법
mongodb://localhost:27017
use chatdb
db.runCommand( { convertToCapped: 'chat', size: 8192 } )
db.chat.stats()
exit
으로 쉘 종료