为什么 MongoDb Atlas UI 不允许我插入一组对象?

时间:2021-07-19 22:16:30

标签: mongodb mongodb-atlas

我正在学习 MongoDb,并尝试通过 MongoDb Atlas UI 插入一个对象,该对象包含一个 members 数组,该数组是一个对象数组 [{x: 1}]。 UI 允许我将 members 设置为数字数组,例如 [1,2 ],但它不允许我将其设置为 [{x: 1}]。知道为什么吗?

对象:

{
    "_id": {
        "$oid": "60f5f833e3a6791569997478"
    },
    "members":  [{x: 1}]
}

它说:Insert not permitted while document contains errors.

界面:

enter image description here

1 个答案:

答案 0 :(得分:1)

字段名称需要用引号括起来,因此对象的正确格式是:

{
    "_id": {
        "$oid": "60f5f833e3a6791569997478"
    },
    "members":  [{"x": 1}]
}
相关问题