This article gives you a comprehensive understanding of Java object serialization and deserialization>>>
When using mongodb, if you encounter the following error:
/home/ec2-user/YourProject/node_modules/mongoose/lib/index.js:391
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)
Generally speaking, the model of mongodb database does not have a chain. At the beginning of yourscript.js, the following lines cannot be missing:
require('./yourModel.js');
const mongoose = require('mongoose');
mongoose.connect("mongodb://localhost/YourDatabase");
const YourModel = mongoose.model('YourModel');
Then, the content of yourmodel.js can be as follows:
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);
Similar Posts:
- [Solved] Vue installs less Error: Failed to compile with 1 errors
- Cannot findmodule’webpack-cli/bin/config-yargs
- [Solved] Module build failed: Error: Cannot find module ‘node-sass’
- How to Solve Error: ENOENT: no such file or directory, scandir ‘..\node_modules\node-sass\vendor’
- Module build failed: Error: Cannot find module ‘node-sass’
- Cannot find module ‘../lib/utils/unsupported.js’
- Node Sass could not find a binding for your current environment: Linux 64-bit with Node.js 7.x
- Causes and solutions of error reporting in require setting dynamic path
- Completely Uninstall Node.js from Mac OS X
- Error: listen eaddinuse: 4000 [How to Solve]