2015-08-28 28 views
1

这是我的模型类;当从java中搜索时,由_id覆盖的Mongo ID

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

此的对象。

我需要从“Id”中找到:128119 但它不允许通过java如何做到这一点。 有没有重写。

回答

1

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

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

在你在你的代码中使用可能是有故障ID和_id 变化将使您的工作库中。

+1

是的,我认为这是一种健康的方式。 –