2017-08-08 112 views
0

考慮以下entitis(EventReactions,事件日誌):春數據MongoDB的查詢

public class EventReaction extends Entity { 

    @Id 
    private String id; 

    private EventLog eventLog; 
    ....  
    //getters and setters 
} 

public class EventLog extends Entity { 

    @Id 
    private String id; 
    .... 
    //getters and setters 
} 

我希望下面的接口

public interface EventReactionRepository extends MongoRepository<T , String>{ 

    Optional<EventReaction> findByEventLog_Id(String id) 

} 

返回它們的eventLog ID爲id的eventReactions。但是,它已經存在於mogoDB中,我的查詢什麼也沒有返回!我的查詢是否正確?

回答

0

更改您的代碼

Optional<EventReaction> findByEventLogId(ObjectId id); 

Optional<EventReaction> result= eventReactionRepository.findByEventLogId(new ObjectId("document-storage-id")); 
獲取 Optional<EventReaction>