Mongodb和Node js

时间:2016-05-31 06:40:56

标签: stack schema mean

我是节点js的新手,我正在尝试使用节点js和mongo DB构建一个app测验引擎。我不确定我需要为测验引擎制作模式。所以任何人都可以帮助我。

5 个答案:

答案 0 :(得分:0)

以下是用户架构的示例...

var userSchema = new Schema({

    name: {
        type: String,
        unique: true,
        required: true
    },
    password: {
        type: String,
        required: true
    }
});

但是就像评论所说的那样,你必须更具体。

答案 1 :(得分:0)

据我所知,测验将由用户提供,并且会有问题。因此,您可以创建两个实体:

i)用户实体 ii)测验/问题实体

用户实体架构:

module.exports = {
   attributes = {
     name: {
        type: String,
        required: true
    },
    password: {
        type: String,
        required: true
    }
    password: {
        type: String,
        required: true
    }
  }
};

质询实体架构:

module.exports = {
   attributes = {
     questionLabel: {
        type: 'String',
        required: true
    },
    choices: {
        type: 'Array',
        required: true
    }
  };

答案 2 :(得分:0)

您好,这是我的架构

enter code here var mongoose = require("mongoose");
var Schema = mongoose.Schema;

var img_schema = new Schema({
    title:{type:String,require:true},
    creator:{type:Schema.Types.ObjectId, ref: "User" },
    extension:{type:String,require:true},
    foto:{type:String,require:true},
    uso:{type:String,require:true}
 });

var Imagen = mongoose.model("Imagen",img_schema);
 module.exports = Imagen;

答案 3 :(得分:0)

This is the example of user schema. you can replace with your requirement.

// User Schema
var UserSchema = mongoose.Schema({
    username: {
        type: String,
        index: true
    },
    password: {
        type: String
    },
    email: {
        type: String
    },
    name: {
        type: String
    },
    profileimage:{
        type: String
    }
});

var User = module.exports = mongoose.model('User', UserSchema);

答案 4 :(得分:0)

我建议您使用猫鼬定义您的mongoDB收集架构。 Mongoose促进了nodejs和mongoDB之间的许多过程。 您可以使用以下命令安装猫鼬:

npm i mongoose

然后创建这样的模式:

import mongoose from 'mongoose';
const { Schema } = mongoose; //Pulling schema out of mongoose object

const QuizEngineSchema = new Schema({
 name: String,
 phoneNumber: Number,
 // other data that you need to save in your model
},
{timestamps: true},
{id: false});

//Plugging the Schema into the model
const QuizEngine = mongoose.Model('QuizEngine',QuizEngineSchema);

export default QuizEngine;

希望这会有所帮助!