Mongodb 批量更新子文档(子数据集)
Mongodb 批量更新子文档(子数据集)
数据样例如下:
{ "_id": ObjectId("638da214663eedfbd7c9db1e"), "dwmc": "宁乡东城污水处理有限公司", "pfkmc": "东城污水处理厂入口", "pwxkzbh": " 914301243256808928001U", "mn": "07310022", "xkpfkwybm": "ZDY001", "data_time": ISODate("2022-11-29T06:00:00.000Z"), "sjc": ISODate("2022-11-29T06:00:00.000Z"), "MeasureData": [ { "wrwzldm": "w00000", "wrwmc": "污水", "ssll": NumberDecimal("0"), "min_value": NumberDecimal("547"), "avg_value": NumberDecimal("559.7"), "max_value": NumberDecimal("571.4"), "cou_value": NumberDecimal("1936"), "sjzt": "2", "flag": "B", "estatus": "0", "clbz": "1", "key": "82aafd9cdd6b4316a5d70d7a42ef7e15", "UploadFlag": 1 }, { "wrwzldm": "w21003", "wrwmc": "氨氮", "ssll": NumberDecimal("0"), "min_value": NumberDecimal("12.679"), "avg_value": NumberDecimal("14.522"), "max_value": NumberDecimal("14.89"), "cou_value": NumberDecimal("28.137"), "sjzt": "2", "flag": "B", "estatus": "0", "clbz": "1", "key": "d8bceadc016b43a5a362124971c75c26", "UploadFlag": 1 }, { "wrwzldm": "w01012", "wrwmc": "悬浮物", "ssll": NumberDecimal("0"), "min_value": NumberDecimal("0.091"), "avg_value": NumberDecimal("0.256"), "max_value": NumberDecimal("0.426"), "cou_value": NumberDecimal("0.497"), "sjzt": "2", "flag": "B", "estatus": "0", "clbz": "1", "key": "c7aec509087241a3ae55cb2a962e8afa", "UploadFlag": 1 }, { "wrwzldm": "w01001", "wrwmc": "pH 值", "ssll": NumberDecimal("0"), "min_value": NumberDecimal("7.526"), "avg_value": NumberDecimal("7.551"), "max_value": NumberDecimal("7.59"), "cou_value": NumberDecimal("14.619"), "sjzt": "2", "flag": "B", "estatus": "0", "clbz": "1", "key": "274bd23c45514acba79bcf13c8798d46", "UploadFlag": 1 }, { "wrwzldm": "w01018", "wrwmc": "化学需氧量", "ssll": NumberDecimal("0"), "min_value": NumberDecimal("116.504"), "avg_value": NumberDecimal("121.01"), "max_value": NumberDecimal("121.911"), "cou_value": NumberDecimal("234.333"), "sjzt": "2", "flag": "B", "estatus": "0", "clbz": "1", "key": "b9ce6d12ee814c01b73b171e0ec5ce9e", "UploadFlag": 1 } ], "WrState": NumberInt("2") }
批量更新脚本:
db.Table.update({"data_time":{"$gte":ISODate("2022-11-20T00:00:00.000Z")}},{$set:{"MeasureData.$[].UploadFlag":1}},{"multi":true})