我是 Spring 框架的新手。我有我的 mongo 文件
{
"_id" : ObjectId("527242d584ae917d8bd75c7b"),
"postTitle" : "Car",
"postDesc" : "rent",
"owner" : ObjectId("526a588f84aed6f41cca10bd"),
"intrest" : []
}
我想要的是搜索具有 id 的文档
"_id" : ObjectId("527242d584ae917d8bd75c7b")
并将其更新为
{
"_id" : ObjectId("527242d584ae917d8bd75c7b"),
"postTitle" : "Car",
"postDesc" : "rent",
"owner" : ObjectId("526a588f84aed6f41cca10bd"),
"intrest" : [
{
"userId" : ObjectId("526a587d84aed6f41cca10bc"),
"timestamp" : ISODate("2013-10-31T11:45:25.256Z")
},
{
"userId" : ObjectId("526a587d84aed6f41cca10bc"),
"timestamp" : ISODate("2013-11-31T11:55:25.256a")
}
]
}
我的域名是
@Document
public class Post {
@Id
private ObjectId _id;
private String postTitle;
private String postDesc;
private ObjectId owner=Global.getCurruser();
private List<Intrest> intrest = new ArrayList<Intrest>();
// Getters and setters
}
@Document
public class Intrest {
private ObjectId userId;
private Date timestamp;
// Getters and setters
}
我应该写什么 upsert 来添加或修改 intrest 数组 [] 中的条目。
请帮忙。