【发布时间】:2019-12-18 20:41:17
【问题描述】:
在 mongodb 架构中,我只想在此架构中添加一个数组,但在插入数据时遇到一些问题,始终返回错误字符串“此库 (validator.js) 仅验证字符串”
在模型中:
let prescriptionSchema = new Schema({
appointment_id: {
required: [true, 'Appointment id is required'],
type :Schema.Types.ObjectId,
ref: 'Appointments'
},
remarks: {
type: String,
},
diagnosis_description:{ type : Array , "default" : [] },
diagnosis: [{
diagnosis_description: {
type: String,
},
}],
investigation: [{
test_name: {
type: String,
},
test_description: {
type: String,
},
}],
medicine: [{
medicine_name: {
type: String,
},
medicine_dosage: {
type: String,
},
medicine_power: {
type: String,
},
}]
},
{timestamps: {
createdAt: 'created_at',
updatedAt: 'updated_at'
}});
在控制器中我只是写了一个控制台日志,所以我的问题是在 mongodb 中,mongo 无法理解然后数组,请帮助.....
In postman :
{
"appointment_id": "5d3ab1a4590ad324b2abdb76",
"remarks" : "Next checkup after one month",
"diagnosis":[
{
"diagnosis_description": "Fiver"
}
],
"investigation":[
{
"test_name" : "Blood",
"test_description" : "Dengu"
},
{
"test_name" : "Blood",
"test_description" : "HIV"
}
],
"medicine":[
{
"medicine_name":"Paracetamol",
"medicine_dosage":"650",
"medicine_power":"AM"
}
]
}
const path = require('path'),
路由器 = 要求('express').Router(),
目录=${path.dirname(__dirname)}/controllers,
helperLib = require(path.resolve('./config/lib/helper_lib'));
这是路线:
let ReadDirectory = new helperLib.read_directory.readDirectory();
let Middleware = new helperLib.middleware();
//@ require all controllers for this module
let fileObj = ReadDirectory.requireFiles(dir);
//@ routes mapping
router
.put('/addprescription', fileObj['prescription.account'].addprescription);
//.get('/prescriptionlist', fileObj['prescription.account'].prescriptionlist)
//.put('/updateprescription', Middleware.decodeToken, fileObj['prescription.account'].updateprescription);
module.exports = {
router: router,
base: '/api/prescription'
};
【问题讨论】:
-
请贴出创建路线的代码。
-
{ "statusCode": 500, "status": "failed", "message": "This library (validator.js) validates only strings" } 这是邮递员的回应
-
代码。我是说特快路线。
-
在控制器中我只是做一个console.log
-
添加路线后请检查
标签: node.js mongodb express mongoose