获取消息存在于控制台中而 UID 不在数据库中
我正在尝试检查 UID 是否存在于数据库中。如果它存在,我希望它不写入数据,否则写入数据。
但由于某种原因,当没有这样的 UID 时,我就会存在。
async function engagements(){
// const db = ;
if (await Engagements.find({uid:"f60c7612-93f5-48b6-8039-94cf5668f6b4"})) {
console.log("exist");
}else{
console.log("does not exist");
}
}
I am trying to check if the UID exists in db. If it exist I want it not to write a data else write a data.
But for some reason I am getting exist when there is no such UID.
async function engagements(){
// const db = ;
if (await Engagements.find({uid:"f60c7612-93f5-48b6-8039-94cf5668f6b4"})) {
console.log("exist");
}else{
console.log("does not exist");
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我找到了解决方案。
.find() 返回一个等于 true 的空数组的情况。
基本上我做了一个 const 并检查数组是否为空
I found the solution.
The case that .find() returns an empty array which is equal to true.
Basically I made a const and checked the array if it is empty or not