gpt4 book ai didi

java - 从java搜索时Mongo Id被_id覆盖

转载 作者:行者123 更新时间:2023-11-30 07:58:35 24 4
gpt4 key购买 nike

这是我的模型类;

 @Document(collection = "answers")
public class answers {


String Body;
String Title;
int CommentCount;
int PostTypeId;
int Score;
String CreationDate;
String LastEditDate;
@Id
String id;

int Id;
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
int AnswerCount;
public String getBody() {
return Body;
}
public void setBody(String body) {
Body = body;
}
public String getTitle() {
return Title;
}
public void setTitle(String title) {
Title = title;
}


public int getAnswerCount() {
return AnswerCount;
}
public void setAnswerCount(int answerCount) {
AnswerCount = answerCount;
}
public int getCommentCount() {
return CommentCount;
}
public void setCommentCount(int commentCount) {
CommentCount = commentCount;
}
public int getPostTypeId() {
return PostTypeId;
}
public void setPostTypeId(int postTypeId) {
PostTypeId = postTypeId;
}
public int getScore() {
return Score;
}
public void setScore(int score) {
Score = score;
}
public String getCreationDate() {
return CreationDate;
}
public void setCreationDate(String creationDate) {
CreationDate = creationDate;
}
public String getLastEditDate() {
return LastEditDate;
}
public void setLastEditDate(String lastEditDate) {
LastEditDate = lastEditDate;
}

}

这是mongodb中的对象

{
"_id" : ObjectId("554a41d9e4afa41988d61713"),
"LastActivityDate" : "2015-01-23T19:52:06.337",
"ParentId" : 128038,
"Body" : "<p>If you can use Java NIO (JDK 1.4 or greater), then I think you're looking for java.nio.channels.FileChannel.lock()</p>&#xa;&#xa;<p><a href=\"http://java.sun.com/j2se/1.5.0/docs/api/java/nio/channels/FileChannel.html#lock(long,%20long,%20boolean)\" rel=\"nofollow\">FileChannel.lock()</a></p>&#xa;",
"OwnerDisplayName" : "KC Baltz",
"OwnerUserId" : 9910,
"LastEditorUserId" : 9910,
"Id" : 128119,
"CreationDate" : "2008-09-24T16:13:36.577",
"LastEditDate" : "2015-01-23T19:52:06.337",
"PostTypeId" : 2,
"Score" : 11,
"CommentCount" : 4
}

这是从 stackoverflow 数据转储中过滤出来的。

我需要从“Id”中查找:128119但它不允许通过java如何做到这一点。有没有什么压倒性的。

最佳答案

尝试将 Id 值更改为不同的值。

db.answers.update({}, {$rename:{"Id":"UUID"}}, false, true);

您在代码中使用的库中的 Id 和 _id 可能有错误改变会让你的工作变得更好。

关于java - 从java搜索时Mongo Id被_id覆盖,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32275414/

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