数据库
首页 > 数据库> > toast和mongodb

toast和mongodb

作者:互联网

module.exports={
    success:function(ctx,data=null){
        ctx.body={
            status:200,
            data:data,
            msg:""
        }
    },
    fail:function(ctx,msg){
        ctx.body={
            status:200,
            data:null,
            msg:msg.message || msg
        }
    },
    // toast:async fun =>{
    //     try{
    //         const data =await fun;
    //         return this.success(ctx,data);
    //       }catch(error){
    //         return fail(ctx,error);
    //       }
    // }
}

  

//添加  删除
const mongoose=require("mongoose");//导入
mongoose.connect("mongodb://127.0.0.1:27017/text")

const tagSchema=new mongoose.Schema({//创建一个模型  对数据进行约束
    // text:String,
    text:{
        type:String,
        minlength:2,
        maxlength:12
    }
})

const contentSchema=new mongoose.Schema({
    title:{
        type:String,
        minlength:6,
        maxlength:12
    },
    content:{
        type:String,
        minlength:10,
        maxlength:50
    },
    top:{
        type:Boolean,
        default:false
    }
})

const uSerSchema=new mongoose.Schema({
    name:{
        type:String,
        minlength:2,
        // maxlength:[12,"用户名最多12个字符串"] 超出显示的内容
        maxlength:[12,"用户名最多12个字符串"]
    },
    password:{
        type:String,
        validate: {
            validator: function(v) {
              return /[a-zA-z0-9_]/.test(v);
            },
            message: "密码只能是6-12位的数字、字母和下划线的任意组合"
          },
    },
    email:{
        type:String,
        validate: {
            validator: function(v) {
              return /\w+@\w+\.\w+/.test(v);
            },
            message: "邮箱格式不正确"
          },
    },
    namegrop:{
        type:String,
        //枚举
        enum: {
            values: ['限制会员','新手上路','组册会员','中级会员','高级会员'],//值
            message: '{VALUE} is not supported'//错误信息
          }
    }
})

const tagModel=new mongoose.model("tag",tagSchema);
const contentModel=new mongoose.model("content",contentSchema);
const uSerModel=new mongoose.model("uSer",uSerSchema);
//tagModel

module.exports={tagModel,contentModel,uSerModel};

  

标签:toast,12,const,String,mongodb,mongoose,new,type
来源: https://www.cnblogs.com/wangruoyi/p/15645295.html