$使用带有 Rust 的另一个字段设置字段[重复]

问题描述 投票:0回答:1

如何使用 Rust 中 MongoDb 中同一文档中的另一个字段设置一个字段? 我尝试了这个,但它只是将“$another_price”字面设置为值

   let update = doc! {
        "$set": doc! {
           "price":  "$another_price"
        }
    };
    coll.update_many(doc! {}, update, None)
mongodb rust
1个回答
1
投票

感谢评论中的建议,终于成功了。

我缺少的是将 $set 语句放入向量中,这表示聚合管道的使用。

let update = vec![doc! {
        "$set": doc! {
           "price":  "$another_price"
        }
    }];
    coll.update_many(doc! {}, update, None)
© www.soinside.com 2019 - 2024. All rights reserved.