保存空数组时强制转换为数组失败

史努比

我正在使用以下架构,并试图保存曾经有一个空数组awaitingApproval但给我一个强制转换错误的文档

{
      awaitingApproval: [
        {
          type: { type: String, enum: ["personal"] },
          originEventId: { type: String, required: true },
          title: { type: String, required: true },
          allDay: { type: Boolean, default: false },
          start: { type: Date, required: true },
          end: { type: Date, required: true },
          color: { type: String, required: true },
          inviteList: [
            {
              accepted: { type: Boolean, default: false },
              user: { type: Schema.Types.ObjectId, ref: "userType" },
              userType: {
                type: String,
                enum: ["IndustryPartner", "User", "School"]
              }
            }
          ]
        }
      ],
      events: [
        {
          type: { type: String, enum: ["personal"] },
          title: { type: String, required: true },
          allDay: { type: Boolean, default: false },
          start: { type: Date, required: true },
          end: { type: Date, required: true },
          originEventId: { type: String, required: true },
          color: { type: String, required: true },
          inviteList: [
            {
              accepted: { type: Boolean, default: false },
              user: { type: Schema.Types.ObjectId, ref: "userType" },
              userType: {
                type: String,
                enum: ["IndustryPartner", "User", "School"]
              }
            }
          ]
        }
      ]
    }

doc我试图执行对象doc.save()如下:

  {
    "_id": "5d6199ce032db770c46bb653",
    "owner": "5c9ba636347bb645e0865283",
    "userType": "User",
    "awaitingApproval": [],
    "events": [
        {
            "allDay": false,
            "_id": "5d61a549032db770c46bb77b",
            "inviteList": [
                {
                    "accepted": false,
                    "_id": "5d62bac4ac9acd56d8aa3ac3",
                    "user": "5c9bf6eb1da18b038ca660b8",
                    "userType": "User"
                },
                {
                    "accepted": true,
                    "_id": "5d62bac4ac9acd56d8aa3ac2",
                    "user": "5c9ba636347bb645e0865283",
                    "userType": "User"
                }
            ],
            "type": "personal",
            "title": "Tfasfds",
            "start": "2019-08-23T22:17:18.000Z",
            "end": "2019-08-25T22:17:18.000Z",
            "color": "blue",
            "originEventId": "5d61a549032db770c46bb77b"
        }
    ],
    "__v": 4
}

我收到以下错误:

日历验证失败:awaitingApproval.0.inviteList:值“ CoreMongooseArray”的数组转换失败

为什么仍然尝试inviteList在空数组中定位

拉吉·库玛(Raj Kumar)

您正在传递_id而不是的邀请列表数组user它应该看起来像:

"inviteList": [
                {
                    "accepted": false,
                    "user": "5c9bf6eb1da18b038ca660b8",
                    "userType": "User"
                },
                {
                    "accepted": false,
                    "user": "5c9ba636347bb645e0865283",
                    "userType": "User"
                }
            ]

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章

char *(数组)强制转换为无符号长+ 1?

将NSPersistentStoreResult强制转换为数组

将char数组强制转换为struct指针

空数组可以转换为任何类型的数组

在强制转换为void *的数组上进行迭代

反转空数组以及要强制转换为的数据类型

Typescript通用数组被强制转换为any []?

从文件读取保存的数组列表(对象)时,类强制转换异常

错误无法使用Mulesoft将数组强制转换为对象

将结构强制转换为数组是否合法?

为什么初始化指针时必须将数组强制转换为type []?

将值从数组强制转换为findViewById id

TypeError:错误#1034:类型强制转换失败:无法将对象转换为数组

将数组强制转换为字符串枚举器时发生运行时错误

将Int数组强制转换为Enum标志

在Python中从列表强制转换为numpy数组问题

将int强制转换为字节数组时的C ++字节顺序

在将AnyObject强制转换为NSMutableDictionary时,Swift类强制转换失败

如何将var强制转换为长数组?

如何从char数组强制转换为double

将对象保存数组转换为JSON

使用JQ将JSON转换为CSV时处理空(空数组)?

将stdClass强制转换为数组-键不可访问

将null强制转换为对象数组是否比强制转换为对象花费更多?

将对象数组转换为键失败

将原始数组转换为装箱数组时如何减少强制转换次数

数组不能被强制转换为整数(TypeError)

当 T 定义为数组时,如何将对象数组强制转换/转换为泛型类型 T?

将对象列表转换为 numpy 数组而不将对象强制转换为数组