- android - RelativeLayout 背景可绘制重叠内容
- android - 如何链接 cpufeatures lib 以获取 native android 库?
- java - OnItemClickListener 不起作用,但 OnLongItemClickListener 在自定义 ListView 中起作用
- java - Android 文件转字符串
我正在创建一个 mongoose Schema,但我得到了一个 MongooseError
。
这是我的方案:
let RestaurantSchema = new Schema({
ratings: {
type: [{
id: Number,
value: Number,
_id: false
}],
default: [
{ id: 1, value: 0 },
{ id: 2, value: 0 },
{ id: 3, value: 0 },
{ id: 4, value: 0 },
{ id: 5, value: 0 }
]
},
menu: [{
ratings: {
type: [{
id: Number,
value: Number,
_id: false
}],
default: [
{ id: 1, value: 0 },
{ id: 2, value: 0 },
{ id: 3, value: 0 },
{ id: 4, value: 0 },
{ id: 5, value: 0 }
]
}
}]
})
这是我得到的错误:
/var/app/node_modules/mongoose/lib/schema/documentarray.js:322
throw new CastError('embedded', valueInErrorMessage,
^
MongooseError: Cast to embedded failed for value "{ id: 5, value: 0 }" at path "rating"
at CastError (/var/app/node_modules/mongoose/lib/error/cast.js:26:11)
at DocumentArray.cast (/var/app/node_modules/mongoose/lib/schema/documentarray.js:322:19)
at DocumentArray.SchemaType.getDefault (/var/app/node_modules/mongoose/lib/schematype.js:616:23)
at EmbeddedDocument.Document.$__buildDoc (/var/app/node_modules/mongoose/lib/document.js:265:22)
at EmbeddedDocument.Document (/var/app/node_modules/mongoose/lib/document.js:61:20)
at EmbeddedDocument [as constructor] (/var/app/node_modules/mongoose/lib/types/embedded.js:31:12)
at new EmbeddedDocument (/var/app/node_modules/mongoose/lib/schema/documentarray.js:70:17)
at DocumentArray.SchemaArray [as constructor] (/var/app/node_modules/mongoose/lib/schema/array.js:67:21)
at new DocumentArray (/var/app/node_modules/mongoose/lib/schema/documentarray.js:31:13)
at Function.Schema.interpretAsType (/var/app/node_modules/mongoose/lib/schema.js:643:16)
at Schema.path (/var/app/node_modules/mongoose/lib/schema.js:563:29)
at Schema.add (/var/app/node_modules/mongoose/lib/schema.js:445:12)
at new Schema (/var/app/node_modules/mongoose/lib/schema.js:99:10)
at Object.<anonymous> (/var/app/models/restaurant.js:12:24)
at Module._compile (module.js:571:32)
at Object.Module._extensions..js (module.js:580:10)
at Module.load (module.js:488:32)
at tryModuleLoad (module.js:447:12)
at Function.Module._load (module.js:439:3)
at Module.require (module.js:498:17)
at require (internal/module.js:20:19)
at Object.<anonymous> (/var/app/controllers/restaurant.js:6:18)
at Module._compile (module.js:571:32)
at Object.Module._extensions..js (module.js:580:10)
at Module.load (module.js:488:32)
at tryModuleLoad (module.js:447:12)
at Function.Module._load (module.js:439:3)
at Module.require (module.js:498:17)
我做错了什么?
最佳答案
不一定与上述情况有关,但出现此错误的情况(如发生在我身上的那样)是模式需要一个对象,但代码试图保存到一个数组。即,如果:
var MySubSchema = new Schema(
{
type: String,
meta: String
}
)
var MySchema = new Schema(
subSchema: MySubSchema,
otherSubSchema: OtherSubSchema
)
但是保存数据的路由/ Controller 如下:
var mySchemaObj = new MySchema(
{mySubSchema: [new MySubSchema( //<-- Shouldn't have array "[" here
{
type: "foo",
meta: "bar"
}
)]
}
)
. . .
. . .
mySchemaObj.save() . . . // <-- This will throw the "Cast to Embedded Failed" error, because MySchema expects a single MySubSchema Object, but the code above instantiates MySubSchema in an array.
关于node.js - Mongoose 错误 : Cast to embedded failed for value,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43356267/
ASIDE:是的,这可以被认为是一个主观问题,但我希望从回答的统计数据中得出结论。 有各种各样的计算设备。它们的物理尺寸、计算能力和电力各不相同。我想知道嵌入式开发人员认为什么是使系统“嵌入式”的决定
当我听到这个时,我总是想到移动设备。但为什么硬件“嵌入”在那里?整个设备不就是硬件吗?为什么个人电脑没有嵌入式硬件系统? 最佳答案 在当今世界,嵌入式仅指具有以下一项或多项特征的系统: 单一用途(即,
我想测试嵌入式 PowerBI 所以我下载了 the sample app能够发布 pbix 文件并嵌入它。 所以我创建了最简单的 PowerBI 文件,可以使用 Azure SQL 制作,使用 Di
我需要问几个关于词嵌入的问题......可能是基本的。 当我们转换一个词的 one-hot 向量时,例如 king [0 0 0 1 0]嵌入向量 E = [0.2, 0.4, 0.2, 0.2] .
我想知道如何将 CEF 添加到我的 Yocto 项目中。此时,我还没有对项目进行任何修改。它由我们的电路板制造商提供。该板有一个ARM 9。 最佳答案 直接在 CEF 论坛上问这个问题是个好主意,可能
实体是否可以访问其 Embedded 对象的 Embedded?例如: @Embeddable public class Address { @Embedded protected A
我有一个类似于这个的 Morphia 架构: @Entity class BlogEntry { @Embedded List comments } @Embedded class B
我的 pom.xml 中有以下插件配置: com.day.jcr.vault maven-vault-plugi
直到现在,我仍然对 Openembedded-core 和 meta-openembedded 中的食谱感到困惑。很多时候,很难将食谱放在正确的目录中。它们真的很相似,但在食谱的内容上似乎如此不同。
我正在尝试使用此处找到的 Tensorflow 运行单词教程的矢量表示: http://www.tensorflow.org/tutorials/word2vec/index.md 第一个脚本 wor
谁能帮我解释一下 power BI premium 和 power BI Embedded 之间的区别? 最佳答案 Power BI Embedded 容量(也称为 SKU)是 billed hour
我在执行一个 MongoDB 请求时遇到了一些麻烦。我在 Node.js 上下文中使用 MongoDB 3.2 和 Mongoose。这是文档: { _id: ObjectId('12345'),
Xcode 常规选项卡中的“嵌入式二进制文件”和构建阶段选项卡中的“嵌入式框架”有什么区别? General 选项卡中的“Linked Frameworks”和 Build Phrases 选项卡中的
我正在尝试执行 maven install在 pom 上,显示的结果是: Grave: SEC5054: Certificate has expired 此结果会在测试执行开始后立即出现。 我一直在搜
我正在研究 ppc32 和 ppc64 架构来为我的编译器实现一个新的后端,但是我对一个函数的序言有疑问,我已经阅读了几个关于 PowerPC 的 IBM 文档,但是我读到的关于堆栈的信息很少.一个程
我大部分时间都在使用 Atmel Studio 等工具和 IDE 开发微 Controller ,并抽象出幕后发生的事情。 假设在这种情况下,我们直接从闪存执行代码,这在嵌入式系统中可能是这种情况。
我刚刚发现我在(Cortex M0)上编写代码的ARM不支持未对齐的内存访问。 现在,在我的代码中,我使用了很多打包结构,并且从未收到任何警告或硬故障,所以当Cortex不允许不对齐访问时,Corte
我正在研究 Uboot bootstrap 。我有一些关于 Bootloader 的功能和它要处理的应用程序的基本问题: Q1:据我所知,引导加载程序用于将应用程序下载到内存中。在互联网上,我还发现引
我想了解基本的RISC架构。经过一些研发,我想使用MIPS架构。但是,我没有获得有关带有MIPS处理器的嵌入式开发板的良好信息。 如果有人可以提出好的董事会建议,将会有很大的帮助。 问候, 拉姆吉 最
考虑我们正在为裸机 MCU 编写固件,即没有操作系统。有人告诉我不可能(非法?)将参数传递给中断处理函数? 我无法准确理解为什么会这样?这有什么问题? 附注。是否可以在某些 RTOS-es、嵌入式 L
我是一名优秀的程序员,十分优秀!