我按用戶(用戶 ID)創建了一個團隊,現在我想搜索該用戶是否存在于團隊中。
exports.start = async (message) => {
const check = await group.find({userID1:message.author.id} ||{userID2:message.author.id} || {userID3:message.author.id})
console.log(check);
}
我的資料庫看起來像這樣
{
"_id" : ObjectId("6173107fcf643f15e1fced83"),
"userID1" : "769819933390667796",
"userName1" : "Davion",
"userID2" : "247276609894219777",
"userName2" : "Davion",
"userID3" : "898413310872006716",
"userName3" : "Davion",
"team" : "3",
"__v" : 0
}
uj5u.com熱心網友回復:
$or 像邏輯或運算子
exports.start = async (message) => {
const check = await group.find({
$and: [
{
$or: [
{ userID1: message.author.id },
{ userID2: message.author.id },
{ userID3: message.author.id }
]
}
]
})
console.log(check);
}
$and 對一個或多個運算式(運算式 1、運算式 2 等)的陣列執行邏輯與運算,并選擇滿足所有運算式的檔案。
exports.start = async (message) => {
const check = await group.find({
$and: [
{ userID1: message.author.id },
{ userID2: message.author.id },
{ userID3: message.author.id }
]
})
console.log(check);
}
轉載請註明出處,本文鏈接:https://www.uj5u.com/net/332648.html
