有没有办法在 mongo 模式上拥有对象实例
我一直在为医院处方管理做后端,我使用了 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
使用 array 您可以这样定义它:
using array you can define it like this: