gpt4 book ai didi

java - MongoDB - 更新文档列表中的对象

转载 作者:行者123 更新时间:2023-12-01 09:20:36 24 4
gpt4 key购买 nike

我有以下文档列表,List<Project> projectList

"projectsList": [
{
"projectNumber": 1
"projectName": "kjsd",
"projectURL": "lkjsand",
"projectDate": "Oct 7, 2016 12:00:00 AM",
"projectOccupation": "kaijiuhdsa",
"projectProposal": "aus asdig agduya"
},
{
"projectNumber": 2
"projectName": "alan walker",
"projectURL": "lkjsand",
"projectDate": "Oct 7, 2016 12:00:00 AM",
"projectOccupation": "kaijiuhdsa",
"projectProposal": "aus asdig agduya"
},
{
"projectNumber": 3
"projectName": "",
"projectURL": "",
"projectOccupation": "",
"projectProposal": ""
}

]

我有两个项目对象,其中包含

Project oldProject= new Project("kjsd","lkjsand","Oct 7, 2016 12:00:00 AM","kaijiuhdsa","aus asdig agduya")

我需要更新

Project newProject= new Project("kjsd","http","Oct 7, 2016 12:00:00 AM","kaijiuhdsa","ocr")

如何使用java驱动程序在mongoDB中用newProject更新oldProject?

最佳答案

我可以在 MongoDB 中回答。我想你可以将它转换成适当的Java方法。

db.col.update(
{"projectsList.projectNumber": 1},
{$set: {
"projectsList.$.projectUrl": "http",
"projectsList.$.projectProposal": "ocr"
}})

关于java - MongoDB - 更新文档列表中的对象,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40189492/

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