1
我目前正在學習Mean Mean教材的Mean Stack。當我在locationSchema
上使用子文檔時遇到此問題。它必須是與ref
財產有關的東西。我如何設法解決這個問題?Mongodb給出了嵌套模式的錯誤
var mongoose = require('mongoose');
// reviewSchema
var reviewSchema = new mongoose.Schema({
author: String,
});
var openingTimeSchema = new mongoose.Schema({
days: {
type: String,
required: true
}
});
// We use openingTimeSchema as a subdocument here
var locationSchema = new mongoose.Schema({
name: {
Type: String,
required: true
},
openingTimes: [openingTimeSchema],
reviews: [reviewSchema]
});
// Build Mongose Schema to models
mongoose.model('Location', locationSchema);
Error
:
TypeError: Undefined type `undefined` at `name.required`
Did you try nesting Schemas? You can only nest using refs or arrays.
at Function.Schema.interpretAsType (loc8r/node_modules/mongoose/lib/schema.js:592:11)
at Schema.path (loc8r/node_modules/mongoose/lib/schema.js:499:29)
at Schema.add (loc8r/node_modules/mongoose/lib/schema.js:389:12)
at Schema.add (loc8r/node_modules/mongoose/lib/schema.js:384:14)
at new Schema (loc8r/node_modules/mongoose/lib/schema.js:92:10)
at Object.<anonymous> (loc8r/app_server/models/locations.js:30:22)
在name的定義中,它應該是'type:String',而不是'Type:string'。 – JohnnyHK
哇錯字。 :o謝謝。 – Bun