MEAN堆栈mongoDB示例(猫鼬)

时间:2019-03-20 09:40:22

标签: node.js mongodb mean-stack

我目前正在用猫鼬编写MEAN堆栈应用程序的后端。 基本上我想要一个名为“ Simulations”的数据库。在此日期数据库中,我想为每个登录到前端的用户(如“ user1”)存储一个集合。在这些集合中,有许多文档,但是结构都相同。

任何人都可以给我一个提示或链接,该怎么做?我几个小时以来一直在Google arround上搜索,但所有示例均与我的应用程序不匹配。我在每个教程中都使用“每个收集一个模型”方法进行了实验。但是,当新用户注册时,如何在运行时添加它们?

我还没有看完...

我的实际代码

// simulation.route.js

const express = require('express');
const app = express();
const simulationRoutes = express.Router();

let Simulation = require('../models/simulation');

// Defined get data(index or listing) route
simulationRoutes.route('/').get(function (req, res) {
  Simulation.find(function (err, simulations){
    if(err){
      console.log(err);
    }
    else {
      res.json(simulations);
    }
  });
});
//nodeServerModel.js

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


var Simulation = new Schema({
  name: {
    type: String,
    required: 'Enter the name of the simulation'
  },
  comment: {
    type: String,
  },
  ...
}
);

const Simulations = mongoose.connection.useDb('Simulations');

module.exports = Simulations.model('User', Simulation);

因此,我想我想要的是通过URL传递用户名,然后需要适当的模型。但是我现在不能为每个用户做所有模型,因为还没有用户。

感谢后端编程方面的帮助和耐心的初学者:)

0 个答案:

没有答案