Morphia 和 howto 更新现有文档字段
我正在尝试更新文档。
我无法从该页面看到/理解如何执行此操作:
http://www.mongodb.org
我的文档如下所示:(这里可能存在一些错误)
@Entity
public class UserData {
private Date creationDate;
private Date lastUpdateDate;
@Id private ObjectId id;
public String status= "";
public String uUid= "";
public UserData() {
super();
this.statistic = new Statistic();
this.friendList = new FriendList();
}
@Embedded
private Statistic statistic;
@Embedded
private FriendList friendList;
@PrePersist
public void prePersist() {
this.creationDate = (creationDate == null) ? new Date() : creationDate;
this.lastUpdateDate = (lastUpdateDate == null) ? creationDate : new Date();
}
}
在该页面上,我看不到任何描述如何更新具有特定 uUid
的 UserData
的地方。
就像“如果 uUid=123567 则更新 UserData.status”。
这就是我认为我应该使用的:
ops=datastore.createUpdateOperations(UserData.class).update("uUid").if uuid=foo..something more here..
它更新所有 UserData
文档,那么如何更新选定的文档呢?
datastore.update(datastore.createQuery(UserData.class), ops);
I am trying to update a document.
I cannot see/understand how to do it from this page:
http://www.mongodb.org
My Document looks as following: (could be some error here)
@Entity
public class UserData {
private Date creationDate;
private Date lastUpdateDate;
@Id private ObjectId id;
public String status= "";
public String uUid= "";
public UserData() {
super();
this.statistic = new Statistic();
this.friendList = new FriendList();
}
@Embedded
private Statistic statistic;
@Embedded
private FriendList friendList;
@PrePersist
public void prePersist() {
this.creationDate = (creationDate == null) ? new Date() : creationDate;
this.lastUpdateDate = (lastUpdateDate == null) ? creationDate : new Date();
}
}
On that page I cannot see any place where they describe how to update my UserData
that has a specific uUid
.
Like "update UserData.status if uUid=123567".
This is what I think I should use:
ops=datastore.createUpdateOperations(UserData.class).update("uUid").if uuid=foo..something more here..
It updates all the UserData
documents so how to update selected ones?
datastore.update(datastore.createQuery(UserData.class), ops);
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我想这就是你想要的:
I guess this is what you want:
吗啡界面有点笨拙,文档也不清楚...但是实际上在 Erik 引用的页面:
...
另外,不同的文档页面展示了一种巧妙的方法来隐藏实体类中繁琐的查询本身:
The morphia interface is a little clumsy and the docs aren't clear... but a method to update only a single, specific document is actually demonstrated on the page Erik referenced:
...
Also, a different documentation page shows a clever way to hide that cumbersome query inside the entity class itself: