我在架構中做錯了嗎?
const mongoose = require("mongoose");
const Schema = mongoose.Schema;
const userSchema = new Schema(
{
username: {
name: String,
required: true,
unique: true,
trim: true,
minlength: 3
},
},
{
timestamps: true
}
);
const User = mongoose.model("User", userSchema);
module.exports = User;
我得到的錯誤
throw new TypeError(`Invalid schema configuration: \`${name}\` is
not ` ^ TypeError: Invalid schema configuration: `True` is not a valid type
uj5u.com熱心網友回復:
我認為name不是貓鼬模式中的有效屬性。嘗試替換name并type更正minlength錯字為minLength:
const userSchema = new Schema(
{
username: {
type: String,
required: true,
unique: true,
trim: true,
minLength: 3
},
},
{
timestamps: true
}
);
uj5u.com熱心網友回復:
您應該將架構更改為以下
const userSchema = new Schema(
{
username: {
type: String,
required: true,
unique: true,
trim: true,
minlength: 3
},
},
{
timestamps: true
}
);
而不是“名稱”,只需使用“型別”
如需進一步參考,請點擊此鏈接https://mongoosejs.com/docs/guide.html
轉載請註明出處,本文鏈接:https://www.uj5u.com/net/438868.html
