0

目前我的文件具有以下结构:

{
    "_id": {
        "$oid": "613d8e089396a2f660d8d9fc"
    },
    "AmbientTemp": {
        "$numberDecimal": "0.22"
    },
    "CasualRiders": 8,
    "Date": {
        "$date": "2011-01-01T00:00:00.000Z"
    },
    "FeltTemp": {
        "$numberDecimal": "0.2727"
    },
    "Holiday": "No",
    "Hour": "1",
    "Humidity": {
        "$numberDecimal": "0.8"
    },
    "Month": "January",
    "RegisteredRiders": 32,
    "Season": "Spring",
    "TotalRiders": 40,
    "Weather": "Cloudy",
    "Weekday": "Saturday",
    "WindSpeed": {
        "$numberDecimal": "0"
    },
    "Year": "2011",
    "WorkingDay": "No",
    "TrueAmbientTemp": {
        "$numberDecimal": "2.34"
    },
    "TrueFeltTemp": {
        "$numberDecimal": "1.9982"
    }
}

我希望使用以下结构将文档嵌套到其中。其中 Environment 将携带环境指标,时间存储与时间相关的指标。

{
    "_id": {
        "$oid": "613d8e089396a2f660d8d9fb"
    },
    "Hour": "0",
    "Time": [{
        "Year": "2011",
        "Date": {
            "$date": "2011-01-01T00:00:00.000Z"
        },
        "Month": "January",
        "Season": "Spring",
        "Weekday": "Saturday",
        "WorkingDay": "No",
        "Holiday": "No"
    }],
    "Environment": [{
        "Weather": "Cloudy",
        "TrueAmbientTemp": {
            "$numberDecimal": "3.28"
        },
        "TrueFeltTemp": {
            "$numberDecimal": "3.0014"
        },
        "Humidity": {
            "$numberDecimal": "0.81"
        },
        "WindSpeed": {
            "$numberDecimal": "0"
        },
        "FeltTemp": {
            "$numberDecimal": "0.2879"
        },
        "AmbientTemp": {
            "$numberDecimal": "0.24"
        }
    }],
    "CasualRiders": 3,
    "RegisteredRiders": 13,
    "TotalRiders": 16
}

如何在 mongo shell 或 compass 中执行此操作,因为我的经验表明只能通过 MongoDB compass 中的编辑文档部分更改一个文档。另外请告知上述嵌套是否合适。TIA。

4

0 回答 0