代码如下:
const UserSchema = new Schema(
{
userId: String,
userName: String,
password: String,
friendList: [
{type: Schema.Types.ObjectId, ref: 'User'}
],
},
{
timestamps: true
}
)
请问如何能保证friendList数组内的用户是唯一的呢
代码如下:
const UserSchema = new Schema(
{
userId: String,
userName: String,
password: String,
friendList: [
{type: Schema.Types.ObjectId, ref: 'User'}
],
},
{
timestamps: true
}
)
请问如何能保证friendList数组内的用户是唯一的呢
5 回答3.2k 阅读✓ 已解决
3 回答2.3k 阅读✓ 已解决
2 回答2.8k 阅读✓ 已解决
1 回答2.4k 阅读✓ 已解决
1 回答2.9k 阅读✓ 已解决
1 回答2k 阅读✓ 已解决
3 回答2.3k 阅读
我自己的解决办法是 插入数据的时候先查friendList列表里有没有userid,有就弹出提示,没有就插入