gpt4 book ai didi

Spring Reactive MongoDB不保存文档

转载 作者:行者123 更新时间:2023-12-04 17:23:02 25 4
gpt4 key购买 nike

我正在尝试保存一个基本文档,但尽管连接到 mongodb 成功......它似乎不想保存。

Spring 原木

2018-10-03 00:17:25.998  INFO 10713 --- [  restartedMain] o.s.b.d.a.OptionalLiveReloadServer       : LiveReload server is running on port 35729
2018-10-03 00:17:26.049 INFO 10713 --- [ restartedMain] o.s.j.e.a.AnnotationMBeanExporter : Registering beans for JMX exposure on startup
2018-10-03 00:17:26.106 INFO 10713 --- [ctor-http-nio-1] r.ipc.netty.tcp.BlockingNettyContext : Started HttpServer on /0:0:0:0:0:0:0:0:8080
2018-10-03 00:17:26.106 INFO 10713 --- [ restartedMain] o.s.b.web.embedded.netty.NettyWebServer : Netty started on port(s): 8080
2018-10-03 00:17:26.112 INFO 10713 --- [ restartedMain] c.l.s.ServiceLegalApplicationKt : Started ServiceLegalApplicationKt in 3.459 seconds (JVM running for 4.201)
2018-10-03 00:17:26.644 INFO 10713 --- [ntLoopGroup-2-2] org.mongodb.driver.connection : Opened connection [connectionId{localValue:3, serverValue:4}] to localhost:27017

应用程序属性
spring.data.mongodb.host=localhost
spring.data.mongodb.port=27017
spring.data.mongodb.database=legal
spring.data.mongodb.repositories.type=reactive
spring.mongodb.embedded.version=4.0.2

基本接口(interface)和类
interface EventRepository: ReactiveMongoRepository<Event, String>

@Document
class Event(id: String, name: String)

尝试一个简单的保存功能
@Service
class SomeService(val eventRepository: EventRepository)
{
fun save() = eventRepository.save(Event(UUID.randomUUID().toString(), "hey"))
}

最佳答案

Mono<Event> response = repository.save(Event(UUID.randomUUID().toString(), "hey"));

保存方式的变化
fun save() = eventRepository.save(Event(UUID.randomUUID().toString(), "hey")).subscribe();

您必须在 Mono 引用上调用 subscribe() 方法才能查看日志或详细信息。

关于Spring Reactive MongoDB不保存文档,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52607311/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com