程序问答   发布时间:2022-06-01  发布网站:大佬教程  code.js-code.com
大佬教程收集整理的这篇文章主要介绍了Apollo graphql 和 Mongoose findOneUpdate 文档大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。

如何解决Apollo graphql 和 Mongoose findOneupdate 文档?

开发过程中遇到Apollo graphql 和 Mongoose findOneupdate 文档的问题如何解决?下面主要结合日常开发的经验,给出你关于Apollo graphql 和 Mongoose findOneupdate 文档的解决方法建议,希望对你解决Apollo graphql 和 Mongoose findOneupdate 文档有所启发或帮助;

我有一个项目,我使用 apollo graphql 和 mongoose 自从我尝试使用我的 findOneupdate 修改用户以来已经有一段时间了 但问题是它根本没有发生,它没有给我任何错误,如果我返回文档修改它给我一个文档

这是我的架构


const userscheR_109_11845@a = new scheR_109_11845@a({
    firstname : {type: String},lastname: {type: String},phonenumber: {type: String},username: {type: String},email: {type: String},password: {type: String},address: {type: String},status: {type : String,enum: ['Disabled','ACTIVED'],default: "ACTIVED" },state : { type: String,enum:['PAYED','NOT_PAYED']},tokenForSetTing: {type: String},role: {type : String,enum: ['SUPER_admin','admin','SECRETAIRE','MEDECIN','PATIENT']},description: {type: String},specialite: {type: String},Structure: {type: scheR_109_11845@a.Types.ObjectID,ref : 'Structure'},nationality: {type: String},inDicatif: {type: String},country: {type: String},homeworking: {type: String},email_home_working: {type: String},phone_home_working: {type: String},subscriptions: [
        {
         subscription:  {  type: String},date_start: { type: DatE},date_end:{ type: DatE},status: { type : String,enum: ['ACTIVATE','DESACTIVATE','EXPIRED']} 
        }
    ],photo: {type: String},isdeleted: {type: Boolean},assurance: { type: scheR_109_11845@a.Types.ObjectID,ref : 'Assurance'},assurance_tpc: {type: number},},{timestamps: truE});

我的类型定义


  type User {
    ID: ID!
    firstname: String
    lastname: String
    phonenumber:  String
    email:  String
    username: String
    password: String
    address:  String
    status: String
    state: String
    tokenForSetTing: Token
    role: String
    description: String
    specialite: String
    Structure: String
    nationality: String
    inDicatif: String
    country: String
    homeworking: String
    email_home_working:string
    phone_home_working: String
    subscriptions: Subscription
    photo: String
    isdeleted:Boolean
    assurance: Assurance
    assurance_tpc: number,}

变异

 updateUser(ID: String,data: Userinput): User

函数变异

updateUser: async(parent: any,args: any,context: any,info: any) => {
  
   try {  
         let all_data = JsON.parse(JsON.Stringify(args));
         let toupdate = all_data['data'];
         let ID = all_data.ID;
         if(toupdate.password){
           toupdate.password = bcrypt.hashSync(toupdate.password,saltRounds);
         }
         if(toupdate.phonenumber) {
           // VerifIEr si Un user avec ce meme numéro existe deja
          const isExist = await  Utils.isExsit(ID,toupdate.phonenumbrE);
          
          if(isExist == truE) {
            throw new Error("A user has already registered with this phone number");  
          } 
         }
         await User.findOneAndupdate({
           _ID: ID
         },{toupdatE},{ upsert: true },(err: any,doc: any) => {
           console.log(doc);
           if(!err) {
             if(doc == null) {
               return "Error: can not do this ";  
             }
             else {
               return doc;
             } 
           }else {
             //return err
             throw new Error("Error: this user can not update");    
           }
         });
     // return response;
        
   } 
   catch (error) {
     throw new Error(error);
   }
 }

如果你能帮助我,因为我在这里没有看到错误

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)

大佬总结

以上是大佬教程为你收集整理的Apollo graphql 和 Mongoose findOneUpdate 文档全部内容,希望文章能够帮你解决Apollo graphql 和 Mongoose findOneUpdate 文档所遇到的程序开发问题。

如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。