嘿,伙計們,
我需要一個功能,當你洗掉一個用戶時,你和那個被洗掉的用戶不會在他們的用戶串列中看到每個或其他。我不知道我怎樣才能做到這一點。你能幫幫我嗎?
非常感謝您!
用戶架構:
const mongoose = require("mongoose");
const userSchema = new mongoose.Schema(
{
userName: {
type: String,
},
deleteList: [{ type: mongoose.Types.ObjectId, ref: "User" }],
beenDeletedList: [{ type: mongoose.Types.ObjectId, ref: "User" }],
}
);
const User = mongoose.model("User", userSchema);
module.exports = UserInfo;
獲取所有過濾的用戶(我不確定如何過濾所有已洗掉的用戶并顯示其余用戶):
exports.getSortedUsers = async (req, res, next) => {
const user = await User.findById(req.body._id);
}
uj5u.com熱心網友回復:
您可以使用$nor運算子從 mongoose find 中排除物件陣列。
在你的情況下,你可以嘗試這樣的事情:
exports.getSortedUsers = async (req, res, next) => {
const users = await User.find({ $nor: beenDeletedList });
}
bedeletedList 是被您阻止(洗掉)的用戶串列。
轉載請註明出處,本文鏈接:https://www.uj5u.com/gongcheng/492382.html
標籤:javascript 节点.js 猫鼬
