这里服务端的user下index保持这样吗
来源:9-14 批量上传书籍实现

qq_蓝骏毅_04076633
2021-04-18
router.post('/addMany' , async(ctx) => { const { key = '', } = ctx.request.body; const path = `${config.UPLOAD_DIR}/${key}`; const excel = loadExcel(path); const sheet = getFirstSheet(excel); const character = await Character.find().exec(); const member = character.find((item) => (item.name === 'member')); const arr = []; sheet.forEach((record) => { const [account, password = config.DEFAULT_PASSWORD] = record; arr.push({ account, password, character: member._id, }); }); await User.insertMany(arr); ctx.body = { code:1, msg:'添加成功', }; });
写回答
3回答
-
qq_蓝骏毅_04076633
提问者
2021-04-19
改了之后也可以拿到xls00 -
qq_蓝骏毅_04076633
提问者
2021-04-19
有点区别
修改:
router.post('/addMany' , async(ctx) => { const { key = '', } = ctx.request.body; const path = `${config.UPLOAD_DIR}/${key}`; const excel = loadExcel(path); const sheet = getFirstSheet(excel); const character = await Character.find().exec(); const member = character.find((item) => (item.name === 'member')); const arr = []; for (let i = 0; i < sheet.length; i++) { let record = sheet[i]; const [account, password = config.DEFAULT_PASSWORD] = record; const one = await User.findOne({ account, }) if (one) { continue; } arr.push({ account, password, character: member._id, }); } await User.insertMany(arr); ctx.body = { code: 1, msg: '添加成功', data: { addCount: arr.length, }, }; });
00 -
然冬
2021-04-19
可以和仓库里的源码比对一下
https://git.imooc.com/coding-450/book-mgr
012021-04-19
相似问题