javascript - 使用节点和猫鼬导出时出错
问题描述
所以,我创建了一些模式,比如跟踪和导出模型,
var mongoose = require('mongoose');
var specSchema = new mongoose.Schema({
name: String,
description:String
});
var qualSchema = new mongoose.Schema({
name: String,
description:String
});
var doctorSchema = new mongoose.Schema({
name: String,
// qualifications:[qualSchema],
// specializations:[specSchema]
});
var Doctor = mongoose.model('Doctor',doctorSchema);
module.exports = Doctor/**please see here**/
这工作正常。
但是后来我想我也想从这个 js 文件中导出模式,所以我将最后一行更改如下:
module.exports = {Doctor,doctorSchema}
我的代码开始失败,然后我意识到如果我写
module.exports = {Doctor} /**i.e add curly braces to it**/
我的代码再次失败。
这就是我们在节点中导出的方式?正确的?但这使我的代码失败。
解决方案
你是如何导入架构的?由于要导出对象,因此应使用点表示法提取模式名称。
const Doctor = require('exportedSchemaPath').Doctor;
推荐阅读
- c# - IIS自动将子文件夹制作成应用程序,为什么?
- firebase - 使用离线持久性关闭 Ionic Firestore 应用程序时会发生什么?
- python - 如何防止 Ansible 的 shell 配置中的条件命令评估?
- mariadb - 创建分区会锁定表?
- html - youtube iframe 视频无法在 Safari 上运行
- c# - 无法停止计划任务
- regex - 如果字符串包含特定单词,则正则表达式跳过部分字符串
- java - 将查询中的 BIT 作为 Prepared Statement 中的参数传递
- angular - 从日期选择器将角度字符串转换为日期
- emacs - Convert a selected region to org table