在下面的代碼中嘗試實現限制結果的數量。首先使用貓鼬查詢從數據庫中獲取所有數據。然后它將過濾基于數據的用戶搜索。那就是結果。我想限制“結果”數組中的數據。不是“視頻”數組。exports.getVideos = async (req, res) => { const word = req.query.keyword ? req.query.keyword : ""; const limitCount = req.query.limit ? parseInt(req.query.limit) : 2 //fetching all data from database try { const videos = await Video.find() //filtering data from based user search const result = videos.filter(v => ["title", "description"].some(prop => v[prop].toLowerCase().includes(word.toLocaleLowerCase()) ) ) //limit the result res.send(result); } catch (error) { res.status(500).send(error); }};
限制顯示數組對象
慕絲7291255
2022-05-14 14:37:37