【问题标题】:Graphql error newUser is not defined while using mongoose使用猫鼬时未定义Graphql错误newUser
【发布时间】:2021-08-23 19:13:27
【问题描述】:

我是 GraphQL 的新手。我试图创建一个注册函数,只有当邀请代码与 mycode 变量匹配时,用户才会保存在 mongo 中。

User.find({mycode:invitationcode
    }).then(code=>{
      if(code){
        console.log("yes")
        const newUser=new User({
        fullName,
        email,
        username,
        password,
        invitationcode,
        mycode
      }).save();
      }else{
        console.log(
          "no"
        )
      }
    })

VSCode 在声明悬停时显示此内容-'newUser' 但从不读取其值。

请帮忙

【问题讨论】:

    标签: mongodb mongoose graphql


    【解决方案1】:
    User.find({mycode:invitationcode
        }).then(async code=>{
          if(code){
            console.log("yes")
            const newUser= await new User({
            fullName,
            email,
            username,
            password,
            invitationcode,
            mycode
          }).save();
          }else{
            console.log(
              "no"
            )
          }
        })
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2021-08-19
      • 2015-11-08
      • 1970-01-01
      • 2018-02-05
      • 2019-03-02
      • 2012-02-02
      • 2020-11-26
      相关资源
      最近更新 更多