java - 如何使用存储库模式更新 mongodb 中的嵌入文档
问题描述
如何使用 Spring Data Repository 更新 MongoDB 中的嵌入式文档。
[{
"_id": 1,
"hotel_name": "test_hotel",
"reviews": [
{
"id": 1,
"rating": "4star",
"username": "test_user"
},
{
"id": 2,
"rating": "4star",
"username": "test_user"
},
{
"id": 3,
"rating": "4star",
"username": "test_user"
}
]
},
{
"_id": 2,
"hotel_name": "test_hotel2",
"reviews": [
{
"id": 1,
"rating": "4star",
"username": "test_user"
},
{
"id": 2,
"rating": "4star",
"username": "test_user"
},
{
"id": 3,
"rating": "4star",
"username": "test_user"
}
]
}
]
例如,在上面的 json 中,我想更新第二家酒店,查看 id 2。请你帮我如何实现这个需求的存储库。谢谢。
解决方案
使用spring stack,你可以使用SpringData来做,你只需要实现一个扩展MongoRepository的接口并使用Update类进行更新。
我找到了一个详细的快速入门示例: https ://www.baeldung.com/spring-data-mongodb-tutorial
推荐阅读
- math - 将错误状态代码中的字节标志转换为 int
- r - R中具有极小值的算术
- mobaxterm - 如何在 Mobaxterm 中关闭语法高亮
- javascript - Fullcalendar V4 通过 documentId 获取初始化日历
- python - NLP - 使用哪种技术对段落标签进行分类?
- python - 从它们来自的句子中标记单词
- kotlin - 将vargs值传递给Kotlin中具有多个参数的另一个函数?
- python - 在pygame中的列表上旋转
- java - 如何使用 JSP 在 Spring MVC 中配置验证检查?
- javascript - 解析月份列表序列后更改