Error: The method where(String) is undefined while using spring boot mongodb
Error: The method where(String) is undefined while using spring boot mongodb
我已经在我的 spring 启动应用程序中添加了 mongodb 依赖项,但是我在 "where" 方法上遇到未定义的错误:
ChangeStreamRequest<Person> request = ChangeStreamRequest.builder()
.collection("person")
.filter(newAggregation(Person.class, match(where("operationType").is("insert"))))
.publishTo(pListener)
.build();
POM 配置:
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-mongodb-reactive</artifactId>
</dependency>
请多多指教
"undefined"的原因是"there is no method where
defined in your class"。
您必须从 Criteria
导入 where
方法。
您可以通过添加以下导入语句来使用 Criteria.where("operationType").is("insert")
。
import org.springframework.data.mongodb.core.query.Criteria;
或者,您可以添加静态导入,如下所示:
import static org.springframework.data.mongodb.core.query.Criteria.where;
现在,您可以直接使用:
where("operationType").is("insert")
我已经在我的 spring 启动应用程序中添加了 mongodb 依赖项,但是我在 "where" 方法上遇到未定义的错误:
ChangeStreamRequest<Person> request = ChangeStreamRequest.builder()
.collection("person")
.filter(newAggregation(Person.class, match(where("operationType").is("insert"))))
.publishTo(pListener)
.build();
POM 配置:
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-mongodb-reactive</artifactId>
</dependency>
请多多指教
"undefined"的原因是"there is no method where
defined in your class"。
您必须从 Criteria
导入 where
方法。
您可以通过添加以下导入语句来使用 Criteria.where("operationType").is("insert")
。
import org.springframework.data.mongodb.core.query.Criteria;
或者,您可以添加静态导入,如下所示:
import static org.springframework.data.mongodb.core.query.Criteria.where;
现在,您可以直接使用:
where("operationType").is("insert")