我编写了以下架构。但是在运行时会给我一个错误-抛出新的TypeError(Invalid schema configuration: \
$ {name}`不是`+ ---有人可以帮我为什么会出现此错误吗?。下面显示的是我的架构,有人可以弄清楚如果我的架构有一些错误。
"use strict";
var mongoose = require('mongoose');
var Schema = mongoose.Schema;
var studentSchema = new mongoose.Schema(
{
$jsonSchema: {
bsonType: "object",
properties: {
name: {
bsonType: "string",
description: "must be a string"
},
teacherId: {
bsonType: "objectId",
description: "must be a Object ID"
}
}
}
})
您正在使用MongoDB本机语法来定义您的架构。如果您使用猫鼬,猫鼬有其自己的语法。请参阅猫鼬documentation。对于您的架构,它将是:
var studentSchema = new mongoose.Schema({
name: { type: String },
teacherId: { type: mongoose.Schema.Types.ObjectId }
})