gpt4 book ai didi

java - 在 mongoRepository 中查找 DocumentObject

转载 作者:行者123 更新时间:2023-12-01 12:39:21 25 4
gpt4 key购买 nike

我是 mongo 数据库的新手。任何人都可以知道如何查询以获取 mongo DB 中的文档。

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]

最佳答案

我已经得到答案了,应该是findByContentParentContentId(parentContentId)

关于java - 在 mongoRepository 中查找 DocumentObject,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25263496/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com