使用MongoDB的时候,如果遇到下面这个错误:

/home/ec2-user/YourProject/node_modules/mongoose/lib/index.js:
throw new mongoose.Error.MissingSchemaError(name);
^
MissingSchemaError: Schema hasn't been registered for model "YourModel".
Use mongoose.model(name, schema)
at new MissingSchemaError (/home/ec2-user/YourProject/node_modules/mongoose/lib/error/missingSchema.js:20:11)
at Mongoose.model (/home/ec2-user/YourProject/node_modules/mongoose/lib/index.js:391:13)
at Object.<anonymous> (/home/ec2-user/YourProject/YourScript.js:4:27)
at Module._compile (internal/modules/cjs/loader.js:722:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:733:10)
at Module.load (internal/modules/cjs/loader.js:620:32)
at tryModuleLoad (internal/modules/cjs/loader.js:560:12)
at Function.Module._load (internal/modules/cjs/loader.js:552:3)
at Function.Module.runMain (internal/modules/cjs/loader.js:775:12)
at startup (internal/bootstrap/node.js:300:19)
at bootstrapNodeJSCore (internal/bootstrap/node.js:826:3)

一般来说是MongoDB数据库的Model没有链上,在YourScript.js的开头,一般下面几行不能少:

require('./yourModel.js');
const mongoose = require('mongoose');
mongoose.connect("mongodb://localhost/YourDatabase");
const YourModel = mongoose.model('YourModel');

然后yourModel.js的内容可以为:

const mongoose = require('mongoose');
const Schema = mongoose.Schema; const YourModelSchema = new Schema({
something1: { type: String, required: '`something1` must be filled', unique: true },
something2: { type: String },
}); module.exports = mongoose.model('YourModel', YourModelSchema);

Solve Error: MissingSchemaError: Schema hasn't been registered for model "YourModel".的更多相关文章

  1. Solve error: Cannot open include file: 'X11/Xlocale.h': No such file or directory

    When you use FLTK with VS2010, you may get the error: fatal error C1083: Cannot open include file: ' ...

  2. Solve Error Debug Assertion Failed Expression vector iterators incompatible Using PCL in Release Mode of VS2010

    When using PCL 1.4.0 in the release mode building under VS2010, we might sometime get the error &quo ...

  3. Solve error LNK2038: mismatch detected for '_ITERATOR_DEBUG_LEVEL': value '0' doesn't match value '2'

    This error happens in Release mode of VS2010, solve this problem by do following: . Go to Project Pa ...

  4. Solve Error: node postinstall sh: node: command not found

    When install the yeoman using the following command: npm install -g yo You might have the following ...

  5. Solve Error: 'NSInvalidArgumentException', reason: '-[UITableView mas_makeConstraints:]: unrecognized selector sent to instance 0x7fa5c402fa00'

    下面是iOS开发用第三方库可能出现的错误,及其解决方法: 1. 'NSInvalidArgumentException', reason: '-[UITableView mas_makeConstra ...

  6. Solve Error: nafxcw.lib(afxmem.obj) : error LNK2005: "void * __cdecl operator new[](unsigned int)" (??_U@YAPAXI@Z) already defined in libcpmt.lib(newaop.obj)

    Error: nafxcw.lib(afxmem.obj) : error LNK2005: "void * __cdecl operator new[](unsigned int)&quo ...

  7. Solve error LNK2001 about pcl::io::vtkPolyDataToPointCloud

    When use function 'pcl::io::vtkPolyDataToPointCloud' in PCL 1.6.0, one may have error as follows: &g ...

  8. Solve Error : Undefined function or variable ‘setInitialWorkingFolder’. Error in matlabrc (line 197)

    When compile program using Visual Studio 2015, Matlab 2016b, and OpenCV 3.1.0, one might get the err ...

  9. Solve Error: 'has incomplete type', foward declaration of 'class x'

    在C++的OOB编程中,有时候我们会遇到这样的错误Error: 'has incomplete type',forward declaration of 'class x',那么是什么原因引起的这个问 ...

随机推荐

  1. css层叠规则,优先级算法

    前言 层叠样式表CSS最基本的一个特性就是层叠.冲突的声明通过层叠进行排序,由此确定最终的文档表示.而这个过程的核心就是选择器及其相关声明的特殊性.重要性.来源及继承机制.本文将详细介绍CSS层叠 特 ...

  2. mysql数据库truncate表时间长处理

    [环境介绍] 系统环境:Linux + mysql 5.7.18 + 主从复制架构 [背景描述] 客户反映用在mysql数据库上truncate一个innode引擎的list分区100G左右表时,耗时 ...

  3. (三)微信小程序首页的分类功能和搜索功能的实现笔记

    就在昨天,微信宣布了微信小程序开发者工具新增“云开发”功能 下载最新的开发者工具,现在无需服务器即可实现小程序的快速迭代! 分类功能和搜索功能的效果图 1.首页分类功能的实现 boxtwo方法(.js ...

  4. 微信app支付的坑

    app支付商户申请,需注册并认证开放平台账号后电脑端登录开放平台官网:open.weixin.qq.com,[管理中心]->[移动应用],选择需要申请支付的应用,点击[查看]->[微信支付 ...

  5. Invalid character found in the request target. The valid characters are defined in RFC 7230 and RFC

    解决Invalid character found in the request target. The valid characters are defined in RFC 7230 and RF ...

  6. Emmet(以前的Zencoding)的使用

    Emmet就是以前的Zencoding div.wrapper#wrapper>div.right+div.left*2>span{nimei$}*3 //. 类名 #id >下面 ...

  7. 微信小程序-制作简易豆瓣笔记

    demo截图: 图书:      电影:        共工欲善其事,必先利其器: 小程序编辑器下载地址 : https://mp.weixin.qq.com/debug/wxadoc/dev/dev ...

  8. vcenter新建虚拟机centos7作为虚拟机模板

    网卡选项 适配器类型算则E1000 Remote console选项 电源选项 加密 打开电源,连接iso安装系统 按一下tab键,修改网卡为eth0 点击Tab,打开kernel启动选项后,增加ne ...

  9. zabbix批量监控域名下nginx的访问50x状态码数量

    背景: 购物车相关的站点某些页面经常出现502,如果超过一些阈值则需要报警给管理员知道 .自动发现脚本的编写 # vim /usr/local/zabbix_agents_3.2.0/scripts/ ...

  10. 将.NET Core部署在Docker

    转载自:ASP.NET Core 2.1 使用Docker运行 1.新建ASP.NET Core项目 新建一个名为“DockerSample”的ASP.NET Core项目 运行程序,页面如下: 2. ...