简体   繁体   English

更改 Mongoose 模式类型不起作用

[英]Changing Mongoose schema type not working

I have a mongoose schema with a property which was a string array.我有一个带有字符串数组属性的猫鼬模式。

docs: [String]

I changed the type to an object array as follows我将类型更改为对象数组,如下所示

docs: [{ url: String, type: String }]

But when I create a new item, the docs field is still validated with the type string and the following error is thrown.但是当我创建一个新项目时,仍然使用类型字符串验证 docs 字段并引发以下错误。

在此处输入图像描述

I even tried dropping the collection and it still not works.我什至尝试删除该集合,但它仍然无法正常工作。

The brackets should be around the type, and not the entire object.括号应该围绕类型,而不是整个对象。 As documented here , instead of your Schema being:如此所述,而不是您的架构:

docs: [{ url: String, type: String }]

It should be它应该是

docs: { url: String, type: [String] }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM