app.post('/api/video', function (req, res) { try { var PageSize = req.body.PageSize; var PageIndex = req.body.PageIndex; if (!PageSize || !PageIndex) { return; } var Search = {}; if (req.body.Search) { Search = { 'name': { $regex: `^.*${req.body.Search}.*`, $options: 'i' } } } var dbo = client.db("db"); dbo.collection('video').find(Search).sort({ upload_at: -1 }).skip(PageSize * PageIndex - PageSize).limit(PageSize).toArray((err, items) => { if (err) { console.log(err) throw err; } dbo.collection('video').countDocuments(Search, function (err, count) { res.end(JSON.stringify({ "result": items, "pageCount": Math.ceil(count / PageSize), "videoCount": count, })); client.close(); }) }); } catch (e) { console.error(e); } });
Design
2019年11月7日 星期四
[紀錄]nodejs Mongodb分頁模糊查詢
歡迎同好一起聊天進步
HI 如果有任何工作機會歡迎透過信箱聯繫我
Hi any jobs welcome to contact me by mail.Marstsaiforjob@gmail.com
resume:https://1drv.ms/w/s!AkEOmv5qDtVoc9Dj4uHhda310E4
訂閱:
張貼留言 (Atom)
沒有留言:
張貼留言