Solve Error: MissingSchemaError: Schema hasn't been registered for model "YourModel".
使用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".的更多相关文章
- 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: ' ...
- 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 ...
- 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 ...
- 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 ...
- Solve Error: 'NSInvalidArgumentException', reason: '-[UITableView mas_makeConstraints:]: unrecognized selector sent to instance 0x7fa5c402fa00'
下面是iOS开发用第三方库可能出现的错误,及其解决方法: 1. 'NSInvalidArgumentException', reason: '-[UITableView mas_makeConstra ...
- 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 ...
- 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 ...
- 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 ...
- Solve Error: 'has incomplete type', foward declaration of 'class x'
在C++的OOB编程中,有时候我们会遇到这样的错误Error: 'has incomplete type',forward declaration of 'class x',那么是什么原因引起的这个问 ...
随机推荐
- DirectX11 With Windows SDK--12 深度/模板状态、平面镜反射绘制
前言 深度/模板测试使用的是与后备缓冲区同等分辨率大小的缓冲区,每个元素的一部分连续位用于深度测试,其余的则用作模板测试.两个测试的目的都是为了能够根据深度/模板状态需求的设置来选择需要绘制的像素. ...
- 工作任务: 批量处理wav音频文件--shell脚本
#!/bin/bash # 处理音频 deal_with_wav() { ) do ) do # gd1_music ./tool/fixbeam2 -c res/fixbeam2.bin -b -i ...
- 第十二节: EF的三种模式(二) 之 ModelFirst模式(SQLServer为例)
一. 简介 顾名思义,ModelFirst是模型优先,是DBFirst的逆向模式,先建立实体数据模型,然后根据实体数据模型来生成数据库,从而驱动整个开发流程.(生成一个空的edmx文件,手动在里面建 ...
- win10设置vscode的终端为管理员权限
右击vscode 点击属性选择兼容性,勾选 “以管理员身份运行此程序” 确定即可!
- 结构体重载运算符&srand&rand
先上代码,再按代码讲解 #include<stdio.h>#include<string.h>#include<stdlib.h>#include<time. ...
- 适合前端学习JS的网站
https://developer.mozilla.org/zh-CN/docs/Web/JavaScript
- 微信支付现金红包接口应用实例代码说明和DEMO详解,适合用来做微信红包营销活动、吸粉利器
本文详细介绍微信红包开发的接口,商户调用接口时,通过指定发送对象以及发送金额的方式发放红包,领取到红包后,用户的资金直接进入微信零钱.后面带有具体调用php实例 总结一下:需要注意的是PEM秘 ...
- Javascript实现的数组降维——维度不同,怎么谈恋爱(修订版)
数组的元素可能是数组,这样一层层嵌套,可能得到一个嵌套很深的数组,数组降维要做的事就是把嵌套很深的数组展开,一般最后得到一个一维数组,其中的元素都是非数组元素,比如数组[1, [2, 3, [4, 5 ...
- 全文搜索引擎Elasticsearch入门实践
全文搜索引擎Elasticsearch入门实践 感谢阮一峰的网络日志全文搜索引擎 Elasticsearch 入门教程 安装 首先需要依赖Java环境.Elasticsearch官网https://w ...
- 在vue2中隐藏elementUI的tab栏
<template> <el-tabs v-model="activeName" @tab-click="handleClick" ref=& ...