20210916 - unique validator
2021-09-16 00:00:00

按照github上的instruction安装了mongoose-unique-validator,并配置了相应的属性。

1
2
3
4
5
6
7
8
9
10
11
12
13
const personSchema = new mongoose.Schema({
name: {
type: String,
required: true,
unique: true
},
number: {
type: String,
required: true
}
})

personSchema.plugin(uniqueValidator)

测试后,同名的联系人的确是无法添加到数据库了。

但是!在前中后面加空格还是可以的,并且每个地方显示空格的数量还不一样。。。

比如VSCode REST Client、服务端的Terminal和数据库,显示的就是输入的空格数(7个)

而网页render后完全没有体现出空格。

在JSON里,只有在最后多出了一个空格(在前面加多个空格,在JSON里面会在前面多出一个空格;在中间加多个空格,在JSON里中间也只会有一个空格)

Untitled

Untitled

Untitled

Untitled

Untitled