相关疑难解决方法(0)

Mongoose:Coffeescript中的递归嵌入式文档

基于这个例子(有效):

var Comment = new Schema();

Comment.add({
    title : { type: String, index: true }
  , date : Date
  , body : String
  , comments : [Comment]
});
Run Code Online (Sandbox Code Playgroud)

我想创建一个CoffeeScript版本

mongoose = require 'mongoose'
Schema = mongoose.Schema

Person = new Schema
Person.add
  mother: Person
  father: Person
Run Code Online (Sandbox Code Playgroud)

但它返回错误,我不明白为什么

TypeError: undefined is not a function
    at CALL_NON_FUNCTION_AS_CONSTRUCTOR (native)
    at Function.interpretAsType (/path/node_modules/mongoose/lib/schema.js:202:10)
    at Schema.path (/path/node_modules/mongoose/lib/schema.js:162:29)
    at Schema.add (/path/node_modules/mongoose/lib/schema.js:110:12)
    at Object.<anonymous> (/path/Models/test.coffee:6:10)
    at Object.<anonymous> (/path/Models/test.coffee:10:4)
    at Module._compile (module.js:411:26)
    at Object.run (/usr/local/lib/node_modules/coffee-script/lib/coffee-script.js:57:25)
    at /usr/local/lib/node_modules/coffee-script/lib/command.js:147:29 …
Run Code Online (Sandbox Code Playgroud)

javascript mongoose mongodb coffeescript

4
推荐指数
1
解决办法
4600
查看次数

标签 统计

coffeescript ×1

javascript ×1

mongodb ×1

mongoose ×1