【问题标题】:How to give Char datatype in nodejs如何在nodejs中给出Char数据类型
【发布时间】:2019-06-24 21:16:34
【问题描述】:

如果可能的话,我想在 nodejs 模型中设置一个 char 数据类型。我尽力找到那个解决方案。 如果不可能,请给我另一种方法。

谢谢

显示错误

字符未定义

型号

const mongoose = require('mongoose'); 
const Schema = mongoose.Schema;

const AdminSchema = new Schema({
    name: {
    type: String,
    required: true
    },
    email: {
    type: Char,
    required: true
    },
    skype_id: {
    type: String
    },
    password: {
    type: String,
    required: true
    }
 });

【问题讨论】:

    标签: node.js reactjs mongodb express mongoose


    【解决方案1】:

    在这里,为您提供一些示例数据类型。

    const mongoose = require('mongoose'); 
    const Schema = mongoose.Schema;
    
    const AdminSchema = new Schema({
        name: {
            type: String, // String Format
            required: true // If required
        },
        first_name: {
            type: String // String format, but not required
        },
        favorite_number: {
          type: Number, // Number format
          get: v => Math.round( v ),
          set: v => Math.round( v ),
          alias: 'i'
        },
        ... // etc
    });
    

    【讨论】:

    • 我想要 char 数据类型的例子,所以请给我 char 数据类型的答案。
    【解决方案2】:

    使用String 类型和maxlength1

    const mongoose = require('mongoose'); 
    const Schema = mongoose.Schema;
    
    const AdminSchema = new Schema({
        name: {
            type: String,
            required: true
        },
        email: {
            type: String,
            required: true,
            maxlength: 1
        },
        skype_id: {
            type: String
        },
        password: {
            type: String,
            required: true
        }
    });
    

    更多信息请访问the docs

    【讨论】:

    • @AmitPatel 当然:)
    猜你喜欢
    • 2022-08-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-11-26
    • 1970-01-01
    • 2017-05-22
    • 1970-01-01
    相关资源
    最近更新 更多