Java DocumentDb-spring-使用其他字段值更新字段
我正在使用来自Spring的DocumentDb,我想对一个字段使用另一个字段的值进行更新 以下查询正在MongoDb控制台中运行:Java DocumentDb-spring-使用其他字段值更新字段,java,spring,mongodb,aggregation-framework,aws-documentdb,Java,Spring,Mongodb,Aggregation Framework,Aws Documentdb,我正在使用来自Spring的DocumentDb,我想对一个字段使用另一个字段的值进行更新 以下查询正在MongoDb控制台中运行: db.mtpProject.update({},[{$set:{“fieldToBeUpdated”:“$myCurrentField”}}])。 如果删除$set之前的[],则该字段不会更新为myCurrentField的值,而是更新为字符串“myCurrentField” 在Java中,我尝试这样执行它: MongoDatabase db=mongoTemp
db.mtpProject.update({},[{$set:{“fieldToBeUpdated”:“$myCurrentField”}}])。
如果删除$set之前的[],则该字段不会更新为myCurrentField的值,而是更新为字符串“myCurrentField”
在Java中,我尝试这样执行它:
MongoDatabase db=mongoTemplate.getDb();
MongoCollection collection=db.getCollection(“myProject”);
collection.updateMany(new Document(),new Document(“$set”),new
文件(“fieldToBeUpdated”和“$myCurrentField”);
但是因为创建它时没有数组,所以只需将fieldtobeupdate的值设置为“$myCurrentField”
我提到我也尝试过使用$addFields和$out,但是DocumentDb不支持$out
聚合聚合聚合=
聚合(
aoc->
新文件(
“$addFields”,
新文档(“fieldToBeUpdated”,“$myCurrentField”),
aoc->新文档(“$out”,“myProject”);
聚合(agg,“myProject”,myProject.class);
我希望使用保存在myCurrentField上的值更新字段,而不是使用字段名。$out现在在Amazon DocumentDB上受支持: