mongodb集合中的Сhange对象

klr1opcd  于 2022-11-22  发布在  Go
关注(0)|答案(1)|浏览(115)

我正在编写一个包含react、mondodb、mongoose和nodejs的全栈项目。
我的路线功能

const handleBlockUser =  () => {
    if(isCheck.length) {
      isCheck.map(async (userId) => {
        console.log(userId)
        const blockUser = await request(`/api/auth/`, 'PUT', {userId}) 
      })
    }
  }

请求函数

const request = useCallback(async (url, method = 'GET', body = null, headers = {}) => {
    setLoading(true)

我的路由

router.put('/', async (req, res) => {
  const {id} = req.body

  User.find(id)
    .then(doc=>{  
         doc.status = tableState;
         return doc.save();
     })
      .then(doc=>res.json(doc))
      .catch(err=>console.log(err))     
})

在按钮中我传递了正确的ID,但在路由的控制台中它是未定义的。为什么?

4ioopgfo

4ioopgfo1#

const request = useCallback(async (url, method = 'GET', body = null, headers = {}) => {

因为你还没有在PUT请求中传递userId。你已经把null设置为主体。在这里传递userId。我不确定你在使用什么库来发送请求。如果你使用axios,这篇文章会有所帮助。
https://stackabuse.com/how-to-make-put-http-request-with-axios/

相关问题