#mongodb
18 messages · Page 1 of 1 (latest)
try to find document where userID is the id which was mentioned and if there is such data just don't add it again
yeah but I cannot always check the database
I want it to reply with a message eg. this user already exists in db
store the data in cache then
to quickly check without doing query search
- get the user id from the message containing mention
- check the database/cache for data where the user is already exists
- if there is such data reply with 'the user is already exists' otherwise create data with that user
Why?
<schema>.findOne({userID: user?.id}) will return null if no document
Or you can always use findOneAndUpdate
oh that's what I were looking for
I made sth like this
let user1 = await UserData.findOne({ userID: user});
if (user1) {
message.channel.send("User Already Exists")
}
thx @dusky umbra
let userId = message.mentions.members.first().id ?? message.guild.members.cache.get(args[0]);
let userData = await UserData.findOne({ userID: userId });
if (userData) {
message.channel.send("User Already Exists")
}
else {
... create the data
}
yeah I had the other one ready
👍
I just did not search so much about mongo