这是我的模特课;
@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>

<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>
",
"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数据转储中过滤掉的。
我需要找到&#34; Id&#34; :128119 但它不允许java如何做到这一点。 有没有压倒一切。
答案 0 :(得分:1)
尝试将Id值更改为不同的值。
db.answers.update({}, {$rename:{"Id":"UUID"}}, false, true);
您在代码中使用的库可能在Id和_id中有错误 改变将使你的工作。