I am developing a kotlin spring boot app and I want to connect my project to Mongo db attlasian database When I run the project I get the following error
"C:\Program Files\Java\jdk-17\bin\java.exe" "-javaagent:C:\Program Files\JetBrains\IntelliJ IDEA Community Edition 2024.1.1\lib\idea_rt.jar=57139:C:\Program Files\JetBrains\IntelliJ IDEA Community Edition 2024.1.1\bin" -Dfile.encoding=UTF-8 -classpath C:\Users\Yodgorbek\Downloads\spring_boot_crash_course\build\classes\kotlin\main;C:\Users\Yodgorbek\Downloads\spring_boot_crash_course\build\resources\main;C:\Users\Yodgorbek\.gradle\caches\modules-2\files-2.1\org.jetbrains.kotlin\kotlin-reflect\1.9.25\73023c38b7b20430232893cf9b556dc8486e07a4\kotlin-reflect-1.9.25.jar;C:\Users\Yodgorbek\.gradle\caches\modules-2\files-2.1\org.jetbrains.kotlinx\kotlinx-coroutines-reactor\1.8.1\e15d01225c75a731e8e2aae41dcade5c895249b7\kotlinx-coroutines-reactor-1.8.1.jar;C:\Users\Yodgorbek\.gradle\caches\modules-2\files-2.1\org.jetbrains.kotlin\kotlin-stdlib\1.9.25\f700a2f2b8f0d6d0fde48f56d894dc722fb029d7\kotlin-stdlib-1.9.25.jar;C:\Users\Yodgorbek\.gradle\caches\modules-2\files-2.1\org.springframework.boot\spring-boot-starter-web\3.4.4\441c0c71f38783c1d34b8bac5f06f1fa6b103274\spring-boot-starter-web-3.4.4.jar;C:\Users\Yodgorbek\.gradle\caches\modules-2\files-2.1\org.springframework.boot\spring-boot-starter-data-mongodb\3.4.4\941461c15abdaf78422c72d3d363c041fa4fbe2a\spring-boot-starter-data-mongodb-3.4.4.jar;C:\Users\Yodgorbek\.gradle\caches\modules-2\files-2.1\org.springframework.boot\spring-boot-starter-data-mongodb-reactive\3.4.4\68dd26bc530963a097473d2e03deae12001d00ec\spring-boot-starter-data-mongodb-reactive-3.4.4.jar;C:\Users\Yodgorbek\.gradle\caches\modules-2\files-2.1\org.springframework.boot\spring-boot-starter-security\3.4.4\796c83e0f08979c87b62d19d7d956d1ea453f4cd\spring-boot-starter-security-3.4.4.jar;C:\Users\Yodgorbek\.gradle\caches\modules-2\files-2.1\org.springframework.security\spring-security-crypto\6.4.4\914088f7c73375ee02cbe69c159b6460dc2f346b\spring-security-crypto-6.4.4.jar;C:\Users\Yodgorbek\.gradle\caches\modules-2\files-2.1\org.springframework.boot\spring-boot-starter-validation\3.4.4\fa0bc381ac02704bb56631c13e33c3be437aa5c\spring-boot-starter-validation-3.4.4.jar;C:\Users\Yodgorbek\.gradle\caches\modules-2\files-2.1\io.projectreactor.kotlin\reactor-kotlin-extensions\1.2.3\dcfc1a3c65a6c0b71767377d3ee614cfbe821541\reactor-kotlin-extensions-1.2.3.jar;C:\Users\Yodgorbek\.gradle\caches\modules-2\files-2.1\io.jsonwebtoken\jjwt-api\0.12.6\478886a888f6add04937baf0361144504a024967\jjwt-api-0.12.6.jar;C:\Users\Yodgorbek\.gradle\caches\modules-2\files-2.1\org.jetbrains.kotlinx\kotlinx-coroutines-reactive\1.8.1\2f13c27465c847461364012da6bd8b4eb0de5082\kotlinx-coroutines-reactive-1.8.1.jar;C:\Users\Yodgorbek\.gradle\caches\modules-2\files-2.1\io.projectreactor\reactor-core\3.7.4\3f258a092f83615275d2b58b1e71d0d172dc374e\reactor-core-3.7.4.jar;C:\Users\Yodgorbek\.gradle\caches\modules-2\files-2.1\org.jetbrains\annotations\23.0.0\8cc20c07506ec18e0834947b84a864bfc094484e\annotations-23.0.0.jar;C:\Users\Yodgorbek\.gradle\caches\modules-2\files-2.1\org.springframework.boot\spring-boot-starter-json\3.4.4\7f7ca72abcab50661b7b5d23f63b3bc2375bb2b3\spring-boot-starter-json-3.4.4.jar;C:\Users\Yodgorbek\.gradle\caches\modules-2\files-2.1\org.springframework.boot\spring-boot-starter\3.4.4\6ad00ebe69a28a5c1c97f80f81920d65e0e4250b\spring-boot-starter-3.4.4.jar;C:\Users\Yodgorbek\.gradle\caches\modules-2\files-2.1\org.springframework.boot\spring-boot-starter-tomcat\3.4.4\4b18ac49cf13ef2c9a98418ebd8fc212a5259da9\spring-boot-starter-tomcat-3.4.4.jar;C:\Users\Yodgorbek\.gradle\caches\modules-2\files-2.1\org.springframework\spring-webmvc\6.2.5\db8f1171041d7091f3de80cffdfb9d6c5fbf3015\spring-webmvc-6.2.5.jar;C:\Users\Yodgorbek\.gradle\caches\modules-2\files-2.1\org.springframework\spring-web\6.2.5\b42d2c0acbe05bad4c849883aa8816c25b6c1d94\spring-web-6.2.5.jar;C:\Users\Yodgorbek\.gradle\caches\modules-2\files-2.1\org.mongodb\mongodb-driver-sync\5.2.1\c837fdf64de3e0211553e1f28ae433ab245fbbc2\mongodb-driver-sync-5.2.1.jar;C:\Users\Yodgorbek\.gradle\caches\modules-2\files-2.1\org.springframework.data\spring-data-mongodb\4.4.4\a8dba3cd85b8881768944b89dee79faa0eda5dc3\spring-data-mongodb-4.4.4.jar;C:\Users\Yodgorbek\.gradle\caches\modules-2\files-2.1\org.mongodb\mongodb-driver-reactivestreams\5.2.1\eab6074c877b0e3a36984bb8efb89f0ce4c7c314\mongodb-driver-reactivestreams-5.2.1.jar;C:\Users\Yodgorbek\.gradle\caches\modules-2\files-2.1\org.springframework.security\spring-security-config\6.4.4\2bb5d949fc3b935a88c701555fdc3af3d0381228\spring-security-config-6.4.4.jar;C:\Users\Yodgorbek\.gradle\caches\modules-2\files-2.1\org.springframework.security\spring-security-web\6.4.4\b33b3eba22ef5242caef0cf3c0575b0cc303519b\spring-security-web-6.4.4.jar;C:\Users\Yodgorbek\.gradle\caches\modules-2\files-2.1\org.springframework\spring-aop\6.2.5\9f436be65bf45ee8643d93e6823d6c81e8f9f91a\spring-aop-6.2.5.jar;C:\Users\Yodgorbek\.gradle\caches\modules-2\files-2.1\org.apache.tomcat.embed\tomcat-embed-el\10.1.39\88ff05c768c4654097ab0a9f2b49368a0877ad76\tomcat-embed-el-10.1.39.jar;C:\Users\Yodgorbek\.gradle\caches\modules-2\files-2.1\org.hibernate.validator\hibernate-validator\8.0.2.Final\220e64815dd87535525331de20570017f899eb13\hibernate-validator-8.0.2.Final.jar;C:\Users\Yodgorbek\.gradle\caches\modules-2\files-2.1\org.reactivestreams\reactive-streams\1.0.4\3864a1320d97d7b045f729a326e1e077661f31b7\reactive-streams-1.0.4.jar;C:\Users\Yodgorbek\.gradle\caches\modules-2\files-2.1\org.jetbrains.kotlinx\kotlinx-coroutines-core-jvm\1.8.1\bb0e192bd7c2b6b8217440d36e9758e377e450\kotlinx-coroutines-core-jvm-1.8.1.jar;C:\Users\Yodgorbek\.gradle\caches\modules-2\files-2.1\com.fasterxml.jackson.datatype\jackson-datatype-jsr310\2.18.3\cc57924cccf42fc852081c36215272f84ffcd991\jackson-datatype-jsr310-2.18.3.jar;C:\Users\Yodgorbek\.gradle\caches\modules-2\files-2.1\com.fasterxml.jackson.module\jackson-module-parameter-names\2.18.3\fa63ae5eb3956b1a6d7a7ead2b513af89dea22e7\jackson-module-parameter-names-2.18.3.jar;C:\Users\Yodgorbek\.gradle\caches\modules-2\files-2.1\com.fasterxml.jackson.datatype\jackson-datatype-jdk8\2.18.3\621558295660935134b171ce2b0d9ad6842ec2ff\jackson-datatype-jdk8-2.18.3.jar;C:\Users\Yodgorbek\.gradle\caches\modules-2\files-2.1\com.fasterxml.jackson.core\jackson-databind\2.18.3\537e3886263e3b3464385040453e92567fd509e2\jackson-databind-2.18.3.jar;C:\Users\Yodgorbek\.gradle\caches\modules-2\files-2.1\org.springframework.boot\spring-boot-autoconfigure\3.4.4\5ebc8c0682374768ee6eac9acf12f41e76762207\spring-boot-autoconfigure-3.4.4.jar;C:\Users\Yodgorbek\.gradle\caches\modules-2\files-2.1\org.springframework.boot\spring-boot\3.4.4\f9dbe14c2e5e35a2cd27156802ea6b7c42ab34fd\spring-boot-3.4.4.jar;C:\Users\Yodgorbek\.gradle\caches\modules-2\files-2.1\org.springframework.boot\spring-boot-starter-logging\3.4.4\1a7bbfd57e0b2d0bde8ffd6aa7a0ebd94e4b0aed\spring-boot-starter-logging-3.4.4.jar;C:\Users\Yodgorbek\.gradle\caches\modules-2\files-2.1\jakarta.annotation\jakarta.annotation-api\2.1.1\48b9bda22b091b1f48b13af03fe36db3be6e1ae3\jakarta.annotation-api-2.1.1.jar;C:\Users\Yodgorbek\.gradle\caches\modules-2\files-2.1\org.springframework\spring-core\6.2.5\d6786db7122037bf605e54e3b35f262a19b8d502\spring-core-6.2.5.jar;C:\Users\Yodgorbek\.gradle\caches\modules-2\files-2.1\org.yaml\snakeyaml\2.3\936b36210e27320f920536f695cf1af210c44586\snakeyaml-2.3.jar;C:\Users\Yodgorbek\.gradle\caches\modules-2\files-2.1\org.apache.tomcat.embed\tomcat-embed-websocket\10.1.39\abf50abbbae651f95dfcf9fae05f919bfa9b7046\tomcat-embed-websocket-10.1.39.jar;C:\Users\Yodgorbek\.gradle\caches\modules-2\files-2.1\org.apache.tomcat.embed\tomcat-embed-core\10.1.39\f6acead04214d5aaea82c2639392208df33b3abe\tomcat-embed-core-10.1.39.jar;C:\Users\Yodgorbek\.gradle\caches\modules-2\files-2.1\org.springframework\spring-context\6.2.5\237de0c3afca2099ab497cc7464726c02b8ab5c5\spring-context-6.2.5.jar;C:\Users\Yodgorbek\.gradle\caches\modules-2\files-2.1\org.springframework\spring-beans\6.2.5\6f8eb671d9905da5a73bc9ab7e703e9fed6a0c3f\spring-beans-6.2.5.jar;C:\Users\Yodgorbek\.gradle\caches\modules-2\files-2.1\org.springframework\spring-expression\6.2.5\cb39181911dabe3b3d9992c4b4da38468726ea72\spring-expression-6.2.5.jar;C:\Users\Yodgorbek\.gradle\caches\modules-2\files-2.1\io.micrometer\micrometer-observation\1.14.5\b23dff6bf07a29f67fdae8f3f3f8f1c78fa7b126\micrometer-observation-1.14.5.jar;C:\Users\Yodgorbek\.gradle\caches\modules-2\files-2.1\org.mongodb\mongodb-driver-core\5.2.1\34aa1e29cdab75c2fd912a6b853319d6936515c6\mongodb-driver-core-5.2.1.jar;C:\Users\Yodgorbek\.gradle\caches\modules-2\files-2.1\org.mongodb\bson\5.2.1\a45b5955870d5c9325531a2fef5fbef1329b7e8a\bson-5.2.1.jar;C:\Users\Yodgorbek\.gradle\caches\modules-2\files-2.1\org.springframework\spring-tx\6.2.5\99ecc1c976f58ad63df7205e18eac628f2f1fa9a\spring-tx-6.2.5.jar;C:\Users\Yodgorbek\.gradle\caches\modules-2\files-2.1\org.springframework.data\spring-data-commons\3.4.4\24bb91254820f1dd3087ae95667e9bb0a6942b23\spring-data-commons-3.4.4.jar;C:\Users\Yodgorbek\.gradle\caches\modules-2\files-2.1\org.slf4j\slf4j-api\2.0.17\d9e58ac9c7779ba3bf8142aff6c830617a7fe60f\slf4j-api-2.0.17.jar;C:\Users\Yodgorbek\.gradle\caches\modules-2\files-2.1\org.springframework.security\spring-security-core\6.4.4\adccc33ba9baf99b4e42436424a4013f89a8806a\spring-security-core-6.4.4.jar;C:\Users\Yodgorbek\.gradle\caches\modules-2\files-2.1\jakarta.validation\jakarta.validation-api\3.0.2\92b6631659ba35ca09e44874d3eb936edfeee532\jakarta.validation-api-3.0.2.jar;C:\Users\Yodgorbek\.gradle\caches\modules-2\files-2.1\org.jboss.logging\jboss-logging\3.6.1.Final\886afbb445b4016a37c8960a7aef6ebd769ce7e5\jboss-logging-3.6.1.Final.jar;C:\Users\Yodgorbek\.gradle\caches\modules-2\files-2.1\com.fasterxml\classmate\1.7.0\e98374da1f2143ac8e6e0a95036994bb19137a3\classmate-1.7.0.jar;C:\Users\Yodgorbek\.gradle\caches\modules-2\files-2.1\com.fasterxml.jackson.core\jackson-annotations\2.18.3\7fa21cf7da4598f8240e4ebd9779249622af1acd\jackson-annotations-2.18.3.jar;C:\Users\Yodgorbek\.gradle\caches\modules-2\files-2.1\com.fasterxml.jackson.core\jackson-core\2.18.3\78f80c259268200e588aa204dd97ecf09b76916e\jackson-core-2.18.3.jar;C:\Users\Yodgorbek\.gradle\caches\modules-2\files-2.1\ch.qos.logback\logback-classic\1.5.18\fc371f3fc97a639de2d67947cffb7518ec5e3d40\logback-classic-1.5.18.jar;C:\Users\Yodgorbek\.gradle\caches\modules-2\files-2.1\org.apache.logging.log4j\log4j-to-slf4j\2.24.3\da1143e2a2531ee1c2d90baa98eb50a28a39d5a7\log4j-to-slf4j-2.24.3.jar;C:\Users\Yodgorbek\.gradle\caches\modules-2\files-2.1\org.slf4j\jul-to-slf4j\2.0.17\524cb6ccc2b68a57604750e1ab8b13b5a786a6aa\jul-to-slf4j-2.0.17.jar;C:\Users\Yodgorbek\.gradle\caches\modules-2\files-2.1\org.springframework\spring-jcl\6.2.5\1b8db3715dc78bd18b60869458d5ee8829ad8e99\spring-jcl-6.2.5.jar;C:\Users\Yodgorbek\.gradle\caches\modules-2\files-2.1\io.micrometer\micrometer-commons\1.14.5\6201a40489ccedc9539c5f7a2c84e9e64702bf10\micrometer-commons-1.14.5.jar;C:\Users\Yodgorbek\.gradle\caches\modules-2\files-2.1\ch.qos.logback\logback-core\1.5.18\6c0375624f6f36b4e089e2488ba21334a11ef13f\logback-core-1.5.18.jar;C:\Users\Yodgorbek\.gradle\caches\modules-2\files-2.1\org.apache.logging.log4j\log4j-api\2.24.3\b02c125db8b6d295adf72ae6e71af5d83bce2370\log4j-api-2.24.3.jar;C:\Users\Yodgorbek\.gradle\caches\modules-2\files-2.1\io.jsonwebtoken\jjwt-impl\0.12.6\ac23673a84b6089e0369fb8ab2c69edd91cd6eb0\jjwt-impl-0.12.6.jar;C:\Users\Yodgorbek\.gradle\caches\modules-2\files-2.1\io.jsonwebtoken\jjwt-jackson\0.12.6\f141e0c1136ba17f2632858238a31ae05642dbf8\jjwt-jackson-0.12.6.jar;C:\Users\Yodgorbek\.gradle\caches\modules-2\files-2.1\org.mongodb\bson-record-codec\5.2.1\47a9b8ef55b63b6a66e1fd69bcf62a6f547468c8\bson-record-codec-5.2.1.jar com.example.spring_boot_crash_course.SpringBootCrashCourseApplicationKt
. ____ _ __ _ _
/\\ / ___'_ __ _ _(_)_ __ __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
\\/ ___)| |_)| | | | | || (_| | ) ) ) )
' |____| .__|_| |_|_| |_\__, | / / / /
=========|_|==============|___/=/_/_/_/
:: Spring Boot :: (v3.4.4)
2025-04-12T11:50:43.092+02:00 INFO 15040 --- [spring_boot_crash_course] [ main] c.e.s.SpringBootCrashCourseApplicationKt : Starting SpringBootCrashCourseApplicationKt using Java 17.0.8 with PID 15040 (C:\Users\Yodgorbek\Downloads\spring_boot_crash_course\build\classes\kotlin\main started by Yodgorbek in C:\Users\Yodgorbek\Downloads\spring_boot_crash_course)
2025-04-12T11:50:43.099+02:00 INFO 15040 --- [spring_boot_crash_course] [ main] c.e.s.SpringBootCrashCourseApplicationKt : No active profile set, falling back to 1 default profile: "default"
2025-04-12T11:50:44.933+02:00 INFO 15040 --- [spring_boot_crash_course] [ main] .s.d.r.c.RepositoryConfigurationDelegate : Bootstrapping Spring Data Reactive MongoDB repositories in DEFAULT mode.
2025-04-12T11:50:45.166+02:00 INFO 15040 --- [spring_boot_crash_course] [ main] .s.d.r.c.RepositoryConfigurationDelegate : Finished Spring Data repository scanning in 222 ms. Found 0 Reactive MongoDB repository interfaces.
2025-04-12T11:50:45.176+02:00 INFO 15040 --- [spring_boot_crash_course] [ main] .s.d.r.c.RepositoryConfigurationDelegate : Bootstrapping Spring Data MongoDB repositories in DEFAULT mode.
2025-04-12T11:50:45.204+02:00 INFO 15040 --- [spring_boot_crash_course] [ main] .s.d.r.c.RepositoryConfigurationDelegate : Finished Spring Data repository scanning in 26 ms. Found 1 MongoDB repository interface.
2025-04-12T11:50:46.003+02:00 INFO 15040 --- [spring_boot_crash_course] [ main] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat initialized with port 8085 (http)
2025-04-12T11:50:46.026+02:00 INFO 15040 --- [spring_boot_crash_course] [ main] o.apache.catalina.core.StandardService : Starting service [Tomcat]
2025-04-12T11:50:46.026+02:00 INFO 15040 --- [spring_boot_crash_course] [ main] o.apache.catalina.core.StandardEngine : Starting Servlet engine: [Apache Tomcat/10.1.39]
2025-04-12T11:50:46.112+02:00 INFO 15040 --- [spring_boot_crash_course] [ main] o.a.c.c.C.[Tomcat].[localhost].[/] : Initializing Spring embedded WebApplicationContext
2025-04-12T11:50:46.114+02:00 INFO 15040 --- [spring_boot_crash_course] [ main] w.s.c.ServletWebServerApplicationContext : Root WebApplicationContext: initialization completed in 2909 ms
2025-04-12T11:50:46.621+02:00 INFO 15040 --- [spring_boot_crash_course] [ main] org.mongodb.driver.client : MongoClient with metadata {"application": {"name": "SpringBootCrashCourseCluster "}, "driver": {"name": "mongo-java-driver|sync|spring-boot", "version": "5.2.1"}, "os": {"type": "Windows", "name": "Windows 10", "architecture": "amd64", "version": "10.0"}, "platform": "Java/Oracle Corporation/17.0.8+9-LTS-211"} created with settings MongoClientSettings{readPreference=primary, writeConcern=WriteConcern{w=majority, wTimeout=null ms, journal=null}, retryWrites=true, retryReads=true, readConcern=ReadConcern{level=null}, credential=MongoCredential{mechanism=null, userName='kyodgorbek', source='admin', password=<hidden>, mechanismProperties=<hidden>}, transportSettings=null, commandListeners=[], codecRegistry=ProvidersCodecRegistry{codecProviders=[ValueCodecProvider{}, BsonValueCodecProvider{}, DBRefCodecProvider{}, DBObjectCodecProvider{}, DocumentCodecProvider{}, CollectionCodecProvider{}, IterableCodecProvider{}, MapCodecProvider{}, GeoJsonCodecProvider{}, GridFSFileCodecProvider{}, Jsr310CodecProvider{}, JsonObjectCodecProvider{}, BsonCodecProvider{}, EnumCodecProvider{}, com.mongodb.client.model.mql.ExpressionCodecProvider@799c8758, com.mongodb.Jep395RecordCodecProvider@6e00837f, com.mongodb.KotlinCodecProvider@63e4484d]}, loggerSettings=LoggerSettings{maxDocumentLength=1000}, clusterSettings={hosts=[127.0.0.1:27017], srvHost=springbootcrashcoursecl.bh4hg4h.mongodb.net, srvServiceName=mongodb, mode=MULTIPLE, requiredClusterType=REPLICA_SET, requiredReplicaSetName='atlas-x5cp0w-shard-0', serverSelector='null', clusterListeners='[]', serverSelectionTimeout='30000 ms', localThreshold='15 ms'}, socketSettings=SocketSettings{connectTimeoutMS=10000, readTimeoutMS=0, receiveBufferSize=0, proxySettings=ProxySettings{host=null, port=null, username=null, password=null}}, heartbeatSocketSettings=SocketSettings{connectTimeoutMS=10000, readTimeoutMS=10000, receiveBufferSize=0, proxySettings=ProxySettings{host=null, port=null, username=null, password=null}}, connectionPoolSettings=ConnectionPoolSettings{maxSize=100, minSize=0, maxWaitTimeMS=120000, maxConnectionLifeTimeMS=0, maxConnectionIdleTimeMS=0, maintenanceInitialDelayMS=0, maintenanceFrequencyMS=60000, connectionPoolListeners=[], maxConnecting=2}, serverSettings=ServerSettings{heartbeatFrequencyMS=10000, minHeartbeatFrequencyMS=500, serverMonitoringMode=AUTO, serverListeners='[]', serverMonitorListeners='[]'}, sslSettings=SslSettings{enabled=true, invalidHostNameAllowed=false, context=null}, applicationName='SpringBootCrashCourseCluster ', compressorList=[], uuidRepresentation=JAVA_LEGACY, serverApi=null, autoEncryptionSettings=null, dnsClient=null, inetAddressResolver=null, contextProvider=null, timeoutMS=null}
2025-04-12T11:50:46.645+02:00 INFO 15040 --- [spring_boot_crash_course] [g4h.mongodb.net] org.mongodb.driver.cluster : Adding discovered server ac-w8nda7l-shard-00-00.bh4hg4h.mongodb.net:27017 to client view of cluster
2025-04-12T11:50:46.707+02:00 INFO 15040 --- [spring_boot_crash_course] [g4h.mongodb.net] org.mongodb.driver.cluster : Adding discovered server ac-w8nda7l-shard-00-01.bh4hg4h.mongodb.net:27017 to client view of cluster
below my kotlin classes controller class
import com.example.spring_boot_crash_course.controllers.NoteController.NoteResponse
import com.example.spring_boot_crash_course.database.model.Note
import com.example.spring_boot_crash_course.database.repository.NoteRepository
import org.bson.types.ObjectId
import org.springframework.web.bind.annotation.*
import java.time.Instant
@RestController
@RequestMapping("/notes")
class NoteController(
private val repository: NoteRepository
) {
data class NoteRequest(
val id: String?,
val title: String,
val content: String,
val color: Long,
)
data class NoteResponse(
val id: String,
val title: String,
val content: String,
val color: Long,
val createdAt: Instant
)
@PostMapping
fun save(
@RequestBody body: NoteRequest): NoteResponse {
val note = repository.save(
Note(
id = body.id?.let { ObjectId(it) } ?: ObjectId.get(),
title = body.title,
content = body.content,
color = body.color,
createdAt = Instant.now(),
ownerId = ObjectId()
)
)
return note.toResponse()
}
@GetMapping
fun getOwnerById(
@RequestParam(required = true) ownerId: String
):List<NoteResponse> {
return repository.findByOwnerId(ObjectId(ownerId)).map {
it.toResponse()
}
}
}
private fun Note.toResponse():NoteController.NoteResponse{
return NoteResponse(
id = id.toHexString(),
title = title,
content = content,
color = color,
createdAt = createdAt
)
}
note model class
package com.example.spring_boot_crash_course.database.model
import org.bson.types.ObjectId
import org.springframework.data.annotation.Id
import org.springframework.data.mongodb.core.mapping.Document
import java.time.Instant
@Document("notes")
data class Note(
val title:String,
val content:String,
val color:Long,
val createdAt: Instant,
val ownerId: ObjectId,
@Id val id:ObjectId = ObjectId.get()
)
below repository
package com.example.spring_boot_crash_course.database.repository
import com.example.spring_boot_crash_course.database.model.Note
import org.bson.types.ObjectId
import org.springframework.data.mongodb.repository.MongoRepository
interface NoteRepository:MongoRepository<Note,ObjectId> {
fun findByOwnerId(ownerId: ObjectId):List<Note>
}
below my Main class
package com.example.spring_boot_crash_course
import org.springframework.boot.autoconfigure.SpringBootApplication
import org.springframework.boot.autoconfigure.mongo.MongoAutoConfiguration
import org.springframework.boot.runApplication
@SpringBootApplication
class SpringBootCrashCourseApplication
fun main(args: Array<String>) {
runApplication<SpringBootCrashCourseApplication>(*args)
}
my application.properties
spring.application.name=spring_boot_crash_course
server.port=8085
spring.data.mongodb.uri=${MONGODB_CONNECTION_STRING}
spring.security.user.password=test
spring.data.mongodb.database=notes
I want to exactly where I am making mistake I have asked many resources chatgbt digged all other resources
I fixed my solution by adding creating new user and password