【问题标题】:Mongodb and Node jsMongodb 和 Node.js
【发布时间】:2016-09-29 01:02:27
【问题描述】:

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

【问题讨论】:

  • 请尽量详细说明您的问题。

标签: stack schema mean


【解决方案1】:

我会建议你使用 mongoose 来定义你的 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;

希望这会有所帮助!

【讨论】:

    【解决方案2】:
    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);
    

    【讨论】:

      【解决方案3】:

      你好,这是我的架构

      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;
      

      【讨论】:

        【解决方案4】:

        据我所知,用户将进行测验,并且会有问题。所以,你可以创建两个实体:

        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
            }
          };
        

        【讨论】:

          【解决方案5】:

          这是一个用户模式的示例...

          var userSchema = new Schema({
          
              name: {
                  type: String,
                  unique: true,
                  required: true
              },
              password: {
                  type: String,
                  required: true
              }
          });
          

          但正如评论所述,您必须更具体。

          【讨论】:

            猜你喜欢
            • 2021-11-28
            • 2013-02-24
            • 2014-03-20
            • 2013-12-30
            • 2014-12-12
            • 2013-08-19
            • 2016-02-03
            • 2012-08-18
            • 1970-01-01
            相关资源
            最近更新 更多