我是mongo db的新手。任何人都可以知道如何查询以获取mongo DB中的Document。
POJO课程:
@Document(collection = "test")
public class Test implements Serializable {
@Field("source")
private String source = null;
@Field("content")
private Content content = null;
@Field("systemTime")
private long systemTime;
}
@Document
public class Content implements Serializable {
@Field("id")
private String tweetId = null;
@Field("parentContentId")
private String parentContentId = null;
}
服务类:
public ServiceClass {
public void hello{
Test savedPayload = repository.save(test);
String parentContentId = test.getContent().getParentContentId();
if (parentContentId != null) {
Test payLoadFound = (Test) repository.findByContent(parentContentId);
}
}
}
public interface Repository extends
MongoRepository<Test, Serializable> {
List<Test> findByCIPContent(
String parentContentId);
}
当我尝试使用内容parentContentId查找测试时,我收到以下异常。
Caused by: org.springframework.data.mapping.PropertyReferenceException: No property c found for type CIPPayload!
at org.springframework.data.mapping.PropertyPath.<init>(PropertyPath.java:75) ~[spring-data-commons-1.8.1.RELEASE.jar:na]
at org.springframework.data.mapping.PropertyPath.create(PropertyPath.java:327) ~[spring-data-commons-1.8.1.RELEASE.jar:na]
at org.springframework.data.mapping.PropertyPath.create(PropertyPath.java:359) ~[spring-data-commons-1.8.1.RELEASE.jar:na]
at org.springframework.data.mapping.PropertyPath.create(PropertyPath.java:307) ~[spring-data-commons-1.8.1.RELEASE.jar:na]
at org.springframework.data.mapping.PropertyPath.from(PropertyPath.java:270) ~[spring-data-commons-1.8.1.RELEASE.jar:na]
at org.springframework.data.mapping.PropertyPath.from(PropertyPath.java:241) ~[spring-data-commons-1.8.1.RELEASE.jar:na]
at org.springframework.data.repository.query.parser.Part.<init>(Part.java:76) ~[spring-data-commons-1.8.1.RELEASE.jar:na]
at org.springframework.data.repository.query.parser.PartTree$OrPart.<init>(PartTree.java:213) ~[spring-data-commons-1.8.1.RELEASE.jar:na]
at org.springframework.data.repository.query.parser.PartTree$Predicate.buildTree(PartTree.java:321) ~[spring-data-commons-1.8.1.RELEASE.jar:na]
at org.springframework.data.repository.query.parser.PartTree$Predicate.<init>(PartTree.java:301) ~[spring-data-commons-1.8.1.RELEASE.jar:na]
at org.springframework.data.repository.query.parser.PartTree.<init>(PartTree.java:85) ~[spring-data-commons-1.8.1.RELEASE.jar:na]
at org.springframework.data.mongodb.repository.query.PartTreeMongoQuery.<init>(PartTreeMongoQuery.java:52) ~[spring-data-mongodb-1.5.1.RELEASE.jar:na]
at org.springframework.data.mongodb.repository.support.MongoRepositoryFactory$MongoQueryLookupStrategy.resolveQuery(MongoRepositoryFactory.java:128) ~[spring-data-mongodb-1.5.1.RELEASE.jar:na]
at org.springframework.data.repository.core.support.RepositoryFactorySupport$QueryExecutorMethodInterceptor.<init>(RepositoryFactorySupport.java:320) ~[spring-data-commons-1.8.1.RELEASE.jar:na]
at org.springframework.data.repository.core.support.RepositoryFactorySupport.getRepository(RepositoryFactorySupport.java:169) ~[spring-data-commons-1.8.1.RELEASE.jar:na]
at org.springframework.data.repository.core.support.RepositoryFactoryBeanSupport.initAndReturn(RepositoryFactoryBeanSupport.java:224) ~[spring-data-commons-1.8.1.RELEASE.jar:na]
at org.springframework.data.repository.core.support.RepositoryFactoryBeanSupport.afterPropertiesSet(RepositoryFactoryBeanSupport.java:210) ~[spring-data-commons-1.8.1.RELEASE.jar:na]
at org.springframework.data.mongodb.repository.support.MongoRepositoryFactoryBean.afterPropertiesSet(MongoRepositoryFactoryBean.java:108) ~[spring-data-mongodb-1.5.1.RELEASE.jar:na]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1612) ~[spring-beans-4.0.6.RELEASE.jar:4.0.6.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1549) ~[spring-beans-4.0.6.RELEASE.jar:4.0.6.RELEASE]
答案 0 :(得分:1)
我得到了答案,应该是findByContentParentContentId(parentContentId)