Mongoose Mixed Schema不起作用

时间:2015-03-08 16:03:43

标签: javascript node.js mongodb mongoose

我正在尝试在ExpressJs中设置混合Schema我尝试使用 mongoose.Schema.Types.Mixed 没有工作并尝试显式如下所示但不幸的是它失败了同样的错误:

  

“C:\ Program Files(x86)\ JetBrains \ WebStorm 9.0.3 \ bin \ runnerw.exe”   “C:\ Program Files(x86)\ nodejs \ node.exe”app.js

     

C:\用户\用户\桌面\ nodekid \ node_modules \节点的RESTful \ lib中\ model.js:247    app.getDetail = app.get;                        ^ TypeError:无法读取未定义的属性'get'       在Function.Model.register(c:\ Users \ User \ Desktop \ nodekid \ node_modules \ node-restful \ lib \ model.js:247:22)       在对象。 (C:\用户\用户\桌面\ nodekid \路由\ api.js:10:8)       在Module._compile(module.js:456:26)       at Object.Module._extensions..js(module.js:474:10)       在Module.load(module.js:356:32)       在Function.Module._load(module.js:312:12)       在Module.require(module.js:364:17)       at require(module.js:380:17)       在对象。 (C:\用户\用户\桌面\ nodekid \ app.js:18:17)       在Module._compile(module.js:456:26)

     

使用退出代码8完成流程

/**
 * Created by User on 3/8/2015.
 */
var  restful = require("node-restful");

var mongoose = restful.mongoose;

var storeSchema = new  mongoose.Schema({
   name: String,
   products: [new mongoose.Schema({
      name : String,
      description : String
   })]

});
module.exports = restful.model("store", storeSchema);


/**
 * Created by User on 3/8/2015.
 */
var express = require("express");

var router = express().Router;

var stores = require ("../models/store");
stores.methods(["get","post","put","delete"]);
stores.register(router,"stores");

module.exports = router;

新错误:

  

C:\用户\用户\桌面\ nodekid \ node_modules \节点的RESTful \ lib中\ model.js:228           app [key](前缀+'/:id([0-9a-fA-F] {0,24} $)?',handlerlist);                   ^ TypeError:对象函数createApplication(){var app = function(req,res,next){       app.handle(req,res,next); };

     

mixin(app,EventEmitter.prototype,false); mixin(app,proto,   假);

     

app.request = { proto :req,app:app}; app.response = {    proto :res,app:app}; app.init();返回应用;没有方法'get'       在Function.Model.registerRoutes(c:\ Users \ User \ Desktop \ nodekid \ node_modules \ node-restful \ lib \ model.js:228:17)       在Function.Model.register(c:\ Users \ User \ Desktop \ nodekid \ node_modules \ node-restful \ lib \ model.js:248:8)       在对象。 (C:\用户\用户\桌面\ nodekid \路由\ api.js:10:8)       在Module._compile(module.js:456:26)       at Object.Module._extensions..js(module.js:474:10)       在Module.load(module.js:356:32)       在Function.Module._load(module.js:312:12)       在Module.require(module.js:364:17)       at require(module.js:380:17)       在对象。 (C:\用户\用户\桌面\ nodekid \ app.js:18:17)

1 个答案:

答案 0 :(得分:0)

在设置路由时,错误发生在api.js中:

var router = express().Router;

只需更改:

var router = express.Router();