首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >需要帮助将疫苗中心与管理、mongo db、意味着堆栈项目联系起来

需要帮助将疫苗中心与管理、mongo db、意味着堆栈项目联系起来
EN

Stack Overflow用户
提问于 2022-01-22 11:46:51
回答 1查看 48关注 0票数 1

嗨,我刚开始开发一个平均堆栈项目,我的任务是我有两个集合--一个是管理的用户,另一个是疫苗中心的用户--我的任务是将一个管理员注册到一个医疗中心,但我不确定如何链接这些集合,因为管理员需要查看注册的医疗中心,然后将它们注册到中心。

user.js (猫鼬模式),

代码语言:javascript
复制
const userSchema = mongoose.Schema({
  username: {type: String, required: true, unique: true},
  password: {type: String, required: true},
  fullname: {type: String, required: true},
  email: {type: String, required: true},
  staffid: {type: String, required: true, unique: true},
  center: {type: String, required: true},
});
userSchema.plugin(uniqueValidator);

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

,,,

center.js

,,,

代码语言:javascript
复制
const mongoose = require('mongoose');


const postSchema = mongoose.Schema({
  cname: {type: String, required: true},
  caddr: {type: String, required: true}
});

module.exports = mongoose.model('Centers', postSchema);

,,,

user.model.service

,,,

代码语言:javascript
复制
export interface User{
  id: string;
  fname: string;
  uname: string;
  email: string;
  pass: string;
  staffid: string;
  center: string;


}

,,,

. name (我计划将中心名称列表显示为下拉列表,以便管理员在注册帐户时选择中心名称),

代码语言:javascript
复制
<mat-form-field appearance="fill">
    <mat-label>Select</mat-label>
    <mat-select >
      <mat-option name="center" *ngFor="let post of posts" value="post">{{post.cname}}</mat-option>

</mat-select>
代码语言:javascript
复制
,,, 

app.js,,,

代码语言:javascript
复制
app.post('/api/user/signup', (req, res, next) => {
  bcrypt.hash(req.body.password, 10)
  .then(hash => {
    const user = new User ({
      username: req.body.username,
      password: hash,
      fullname: req.body.fullname,
      email: req.body.email,
      staffid: req.body.staffid,
      center: req.body.center




    });
    user.save()
    .then(result => {
      res.status(201).json({
        message: 'user registered',
        result: result
      });
    })
    .catch(err =>{
      res.status(500).json({
        error:err
      });
  });
});
});

,,,

EN

回答 1

Stack Overflow用户

发布于 2022-01-22 12:19:19

根据您的描述,我认为您需要三个数据库表或三个mongoose.Schema

一种用于疫苗接种中心:类似于用于(管理)用户的center.js

  • one :类似于您的user.js,但不包括center property

  • ,另一种用于将用户分配到中心:

代码语言:javascript
复制
mongoose.Schema({
  user: {type: schema.type.objID, ref: "Users", required: true},
  center: {type: schema.type.objID, ref: "Centers", required: true}
});

如果一个用户可以被分配到多个疫苗接种中心,则需要额外的关联模式。

这对你的要求有帮助吗?

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/70812475

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档