我在 Mongodb 中有如下所示的文档:
现在,我想转到一个基于特定“_id
”的文档,对于该文档,我想转到“计划”列表,其中有几个特定日期(不仅是一个日期,但不止一个),我想将状态更新为“已预订”。我浏览了此链接,
How to apply update using Filtered positional operator with arrayFilters
但是在 MongoTemplate 类中,updateMulti
方法不接受 updateOption
参数。有人可以帮忙吗
我出去了。对于任何建议,我们将不胜感激。谢谢。
注意:我使用的是 spring-data 版本“2.0.3.RELEASE”,MongoDB 驱动版本是 v3.6.4。
下面是文档:
{
"_id": "x1",
"timeZone": "America/Los_Angeles",
"schedule": [
{
"Date": "2018-07-10T00:00:00.000Z",
"status": "AVAILABLE"
},
{
"Date": "2018-07-10T00:30:00.000Z",
"status": "AVAILABLE"
},
{
"Date": "2018-07-10T08:00:00.000Z",
"status": "AVAILABLE"
}
],
"_class": "com.scheduler.persistance.model.Calendar"
}
最佳答案
它很快就会在 spring-data-mongodb 中可用。请参阅:https://github.com/spring-projects/spring-data-mongodb/pull/656
使用它看起来像:
new Update()
.set("grades.$[element]", 100)
.filterArray(Criteria.where("element").gte(100));
与此同时,您应该能够将它与他们的快照 Maven 存储库一起使用:
<dependency>
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-mongodb</artifactId>
<version>2.2.0.DATAMONGO-2215-SNAPSHOT</version>
</dependency>
<repository>
<id>spring-libs-snapshot</id>
<name>Spring Snapshot Repository</name>
<url>https://repo.spring.io/libs-snapshot</url>
</repository>
关于mongodb - 如何在 spring-data mongodb 中将 updateOption 与 arrayFilters 一起使用?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51225487/