Answer the question
In order to leave comments, you need to log in
Why does a model with a Number field accept and store a string there?
Here is such a model, we write there and put a string in the id and then the string is written to the database
new Schema({
id: {
type: Number,
unique: true,
}
});
User.findOne({ id: 123})
User.findOne({ id: "123"})
Answer the question
In order to leave comments, you need to log in
You can try adding validation mongoosejs.com/docs/validation.html :
new Schema({
id: {
type: Number,
unique: true,
validate: {
validator: value => typeof value === 'number',
message: 'Invalid id type'
},
}
});
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question