java - Spring Aggregation更新多个数组元素
问题描述
当它们的 ID 存在于列表中时,我正在尝试更新嵌套数组中的许多对象。
这是文档结构
{
id: p00,
children: [{
id: c00,
value: false
},
{
id: c01,
value: false
},
{
id: c02,
value: false
}
]
}
我想更新所有数组元素value=true
ifid=p00
和children.id in [c00, c01]
.
使用 aMatchOperation
查找 id=p00 并传递给AggregationUpdate
,我什至无法更新所有数组元素。
MatchOperation matchStage = Aggregation.match(
new Criteria("id").is("p00"));
AggregationUpdate update = AggregationUpdate.newUpdate(matchStage)
.set("children.$.value").toValue(true);
template.update(Parent.class)
.apply(update)
.all();
抛出异常:
org.springframework.dao.DataIntegrityViolationException: Invalid $set :: caused by :: FieldPath field names may not be empty strings.; nested exception is com.mongodb.MongoWriteException: Invalid $set :: caused by :: FieldPath field names may not be empty strings.
有什么问题?$ 语法应该返回嵌套数组元素。
解决方案
推荐阅读
- python - matplotlib:TypeError:float()参数必须是字符串或数字,而不是“AxesSubplot”
- java - 我收到一个错误 E/RecyclerView: No adapter attach; 跳过布局
- webpack - NPM 开始:SCRIPTS 的 INVALID VALUES 错误(Windows)
- symfony - JS注入后的PHP抓取页面
- postgresql - Citus 在我的测试环境中没有横向扩展
- ruby-on-rails - 尝试使用表单对象设计模式但收到此错误:ActiveModel::UnknownAttributeError in PersonalTrainersController#create
- c - 我在实现堆栈数据结构时遇到分段错误
- django - Django:没有名为“django_haystack”的模块,但我认为它就在这里
- java - 如何将常规 for 循环转换为 java 8 流
- cmake - 如何在没有完整路径的情况下链接静态库?