我正面临着Moongoose js的问题
这是我的节点js代码:
var mongoose=require('moongoose');
var test=mongoose.Schema({test:String})
module.exports = mongoose.model('test',test);
运行此代码时,节点js抛出:
var test=mongoose.Schema({test:String})
^
TypeError: **mongoose.Schema is not a function**
at Object.<anonymous> (H:\TodoList\Model\TodoListModel.js:4:19)
at Module._compile (module.js:652:30)
at Object.Module._extensions..js (module.js:663:10)
at Module.load (module.js:565:32)
at tryModuleLoad (module.js:505:12)
at Function.Module._load (module.js:497:3)
at Module.require (module.js:596:17)
at require (internal/module.js:11:18)
at Object.<anonymous> (H:\TodoList\app.js:9:10)
at Module._compile (module.js:652:30)
at Object.Module._extensions..js (module.js:663:10)
at Module.load (module.js:565:32)
at tryModuleLoad (module.js:505:12)
at Function.Module._load (module.js:497:3)
at Function.Module.runMain (module.js:693:10)
at startup (bootstrap_node.js:188:16)
如果我将此代码更改为以下格式:
var mongoose=require('moongoose');
var Schema = mongoose.Schema;
var test=new Schema({test:String})
module.exports = mongoose.model('test',test);
该代码抛出:
TypeError: **Schema is not a constructor**
请帮助我解决此代码错误。
答案 0 :(得分:0)
require('mongoose');
是您写的require('moongoose');
一个o
的错字:))