【发布时间】:2020-12-30 19:27:42
【问题描述】:
(node:37532) UnhandledPromiseRejectionWarning: MongoError: E11000 duplicate key error collection: aio.users index: _id_ dup key: { _id: "751868484832460840" }
即使在过滤掉重复项后我也会得到这个?我正在尝试为我的不和谐机器人的每个公会中的每个用户创建一个用户对象。这是我的代码。
aio.users.cache.forEach(async (user) =>{
let userObject = await userList.find(uo => uo._id === user.id)
if(!(userObject)){
let newUser = await User.create({
'_id': user.id,
'username': user.tag,
'avatarURL': user.avatarURL(),
'description': `Hi! I'm ${user.username}!`,
'accountcreated': user.createdAt
})
userList.push(newUser)
globalGuild.markModified('users');
return globalGuild.save();
} return;
})
在数据库中,即使在用户下也没有任何对象,所以它甚至没有任何重复。
【问题讨论】:
标签: node.js database mongodb mongoose discord