Mongo 从 java 搜索时被 _id 覆盖

Mongo Id overided by _id when search from java

这是我的模型class;

 @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
}

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

我需要从 "Id" 中找到:128119 但它不允许 java 怎么做。 有没有覆盖。

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

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

您在代码中使用的库中的 Id 和 _id 可能存在错误 改变将使你的工作。