【问题标题】:Why doesn't the MongoDb Atlas UI let me insert an array of objects?为什么 MongoDb Atlas UI 不允许我插入对象数组?
【发布时间】:2021-07-20 06:52:54
【问题描述】:

我正在学习 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.

用户界面:

【问题讨论】:

  • x 也需要用双引号括起来吗?
  • @MontgomeryWatts 我现在感觉很蠢。非常感谢。如果你想回答这个问题,我会接受。
  • 没问题,我去过!

标签: mongodb mongodb-atlas


【解决方案1】:

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

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

【讨论】:

    猜你喜欢
    • 2019-12-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-09-26
    • 1970-01-01
    • 2016-08-21
    相关资源
    最近更新 更多