4

次のように数字を使用するスキーマがあります。

var mongoose = require('mongoose')
    , Schema = mongoose.Schema
    , ObjectId = Schema.Types.ObjectId
    , Mixed = Schema.Types.Mixed
    , Number = Schema.Types.Number
    , Date = Schema.Types.Date

var ItemSchema = new Schema({
    quantity:{type:Number, required:true, min:1},
    category:{type:String, required:true, enum:categoryList},
    description:{type:String, required:true},
    cost:{type:Number, required:true, min:0, default:0},
    appraisedValue:{type:Number, min:0, default:0},
    appraisedOn:Date,
    purchasedOn:Date,
    purchasedFrom:String,
    brand:String,
    dynamicFieldList:[DynamicFieldSchema]
})
exports.ItemSchema = ItemSchema
exports.Item = mongoose.model('Item', ItemSchema)

しかし、アプリケーションを実行しようとすると、TypeError:Undefined typeat'quantity'を受け取ります。数量値がコメント化されている場合、これは「コスト」でも発生します。

スタックトレースは次のとおりです。

C:\Users\a\Documents\Git\has-inventory.js\node_modules\mongoose\lib\schema.js:325
throw new TypeError('Undefined type at `' + path +

TypeError: Undefined type at `quantity`
  Did you try nesting Schemas? You can only nest using refs or arrays.
at Function.Schema.interpretAsType (C:\Users\a\Documents\Git\has-inventory.js\node_modules\mongoose\lib\schema.js:325:11)
at Schema.path (C:\Users\a\Documents\Git\has-inventory.js\node_modules\mongoose\lib\schema.js:268:29)
at Schema.add (C:\Users\a\Documents\Git\has-inventory.js\node_modules\mongoose\lib\schema.js:200:12)
at new Schema (C:\Users\a\Documents\Git\has-inventory.js\node_modules\mongoose\lib\schema.js:69:10)
at Object.<anonymous> (C:\Users\a\Documents\Git\has-inventory.js\domain\inventory.js:34:18)
at Module._compile (module.js:449:26)
at Object.Module._extensions..js (module.js:467:10)
at Module.load (module.js:356:32)
at Function.Module._load (module.js:312:12)
at Module.require (module.js:362:17)
4

1 に答える 1

6

次の2行を削除します。

, Number = Schema.Types.Number
, Date = Schema.Types.Date

代わりに、組み込みのJavaScriptNumberDateタイプをスキーマ定義で使用する必要があります。

于 2012-09-21T00:43:31.447 に答える