have I done something wrong in the schema?
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;
The error I get
throw new TypeError(`Invalid schema configuration: `${name}` is not ` + ^ TypeError: Invalid schema configuration: `True` is not a valid type
Answers:
Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.
Method 1
I think name
is not valid attribute in mongoose schemas. Try to replace name
by type
and correct the minlength
typo to minLength
:
const userSchema = new Schema( { username: { type: String, required: true, unique: true, trim: true, minLength: 3 }, }, { timestamps: true } );
Method 2
You should change the schema to below
const userSchema = new Schema( { username: { type: String, required: true, unique: true, trim: true, minlength: 3 }, }, { timestamps: true } );
instead of ‘name’ just use ‘type’
For further reference follow this link https://mongoosejs.com/docs/guide.html
All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0