有没有办法在 mongo 模式上拥有对象实例

发布于 2025-01-10 06:10:02 字数 1135 浏览 0 评论 0原文

我一直在为医院处方管理做后端,我使用了 mongo 和 Node。当使用 mongo 模式时,不知道医生会写多少药物,我必须手动为该模式编写所有药物。所以有没有一种方法可以自动化它..我是 mongo 新手,所以请帮助我。


const presmod = mongoose.Schema({
    HospName : {
        type: String,
        required : true
    },
    DoctorId: {
        type : String,
        required : true
    },
    PatientName : {
        type: String,
        required : true
    },
    PatientId : {
        type: String,
        required : true
    },
    drugs : {
        drug1 : {date:{type: Date, required: true},Name: {type: String, required: true}},
        drug2 : {date:{type: Date, required: true},Name: {type: String, required: true}},
        drug3 : {date:{type: Date, required: true},Name: {type: String, required: true}},
        drug4 : {date:{type: Date, required: true},Name: {type: String, required: true}},
        drug5 : {date:{type: Date, required: true},Name: {type: String, required: true}},
        drug6 : {date:{type: Date, required: true},Name: {type: String, required: true}},
    },
    
})

module.exports = mongoose.model("prescription", presmod)

不用手动输入药物 1,药物 2 ... 药物 n ,.. 有没有办法自动化?

I have been doing back end for a hospital prescription management and I used mongo and node for that.. when using the mongo schema, not knowing how many drugs will the doctor write I have to manually write all the drugs for the schema.. so is there a way to automate it .. am new to mongo so help me please.


const presmod = mongoose.Schema({
    HospName : {
        type: String,
        required : true
    },
    DoctorId: {
        type : String,
        required : true
    },
    PatientName : {
        type: String,
        required : true
    },
    PatientId : {
        type: String,
        required : true
    },
    drugs : {
        drug1 : {date:{type: Date, required: true},Name: {type: String, required: true}},
        drug2 : {date:{type: Date, required: true},Name: {type: String, required: true}},
        drug3 : {date:{type: Date, required: true},Name: {type: String, required: true}},
        drug4 : {date:{type: Date, required: true},Name: {type: String, required: true}},
        drug5 : {date:{type: Date, required: true},Name: {type: String, required: true}},
        drug6 : {date:{type: Date, required: true},Name: {type: String, required: true}},
    },
    
})

module.exports = mongoose.model("prescription", presmod)

instead of manually typing drug 1, drug 2 ... drug n ,.. is there a way to automate it?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

心的憧憬 2025-01-17 06:10:02

使用 array 您可以这样定义它:

drugs: [{
  date: {
    type: Date,
    required: true
  },
  Name: {
    type: String,
    required: true
  }
}]

using array you can define it like this:

drugs: [{
  date: {
    type: Date,
    required: true
  },
  Name: {
    type: String,
    required: true
  }
}]

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文