Mongodb 批量更新子文档(子数据集)

parss2个月前 (12-12)Mongodb90

Mongodb 批量更新子文档(子数据集)

image.png



数据样例如下:

{
    "_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})



相关文章

Mongodb 查询条件,按时间段查询

mongodb查询语句运算符(>) 大于 - $gt (<) 小于 - $lt (>=) 大于等于 ...

Mongodb 类似 MsSql中 In关键字使用

Mongodb 类似 MsSql中in关键字的使用:db.T_ZXJC_FSXSSJB.find({"_id":{$in:[ObjectId("636875208876d...

发表评论

访客

◎欢迎参与讨论,请在这里发表您的看法和观点。