2017-07-19 8 views
0

json照会メソッドを使用して検索しようとしています。たとえば、エンタープライズエンティティを「EnterpriseA」という名前で検索する必要があります。しかし、nameプロパティはコンテンツの一部であり、生のjsonです。実行することは可能ですか?これは私のエンティティであるMongoRepositoryでSpringデータを使用して生のjsonを照会する方法

"content": "{\"name\":\"EnterpriseA\",\"email\":\"[email protected]\",\"address\":[{\"id\":1,\"description\":\"some description...\"},{\"id\":2,\"description\":\"some description...\"}]}" 

@Document(collection = "enterprise") 
public class Enterprise { 
    @Id 
    private String id; 

    @Indexed(unique = true) 
    private String content; 

    @Indexed(unique = false) 
    private Long companyId; 
    //... 
} 

マイリポジトリ:

@Repository 
public interface EnterpriseDao extends MongoRepository<Enterprise, 
String> { 
    @Query("{ 'content' : ?0 }") 
    Enterprise findByName(String name); 
} 

私は私が何かを見つけるしたいと思います

内容は、次のような値をとることができます間違っている。

答えて

0

Document.parseを使用して、キーnameの値を取得できます。

何か

よう
String content = "{\"name\":\"EnterpriseA\",\"email\":\"[email protected]\",\"address\":[{\"id\":1,\"description\":\"some description...\"},{\"id\":2,\"description\":\"some description...\"}]}"; 
Document doc = Document.parse(content); 
String name = doc.getString("name"); 
Enterprise enterprise = enterpriseDao.findByName(name); 
関連する問題