2017-04-06 55 views
0

在MongoDB/NodeJs(帶Mongoose)中保存以下模式時出現此錯誤: 未捕獲RangeError:超出最大調用堆棧大小。MongoDB - NodeJs - 超出最大調用堆棧大小

var mongoose = require('mongoose'); 

const Attribute = new mongoose.Schema({ 
    context: String, 
    format: String, 
    measurand: String, 
    location: String, 
    unit: String 
}); 

const Value = new mongoose.Schema({ 
    value: Number, 
    attributes: Attribute 
}); 

module.exports = mongoose.model('MeterValue',{ 
    chargeBoxID: {type: String, ref: 'ChargingStation'}, 
    connectorId: Number, 
    transactionId: Number, 
    timestamp: Date, 
    values: [Value] 
}); 

任何想法:

,當我在我的架構在陣列中添加細節會出現這種情況?

在此先感謝! Serge。

回答

0

我想你必須爲數組中的模型定義一個額外的模式。

喜歡的東西:

const AddressSchema mongoose.Schema({ 
 
    address1: { type: String }, 
 
    address2: { type: String }, 
 
}); 
 

 
... 
 

 
module.exports = mongoose.model('Person',{ 
 
    _id: String, 
 
    name: String, 
 
    address: [ AddressSchema ], 
 
});

+0

感謝了很多,但我也試過這個沒有成功:( – LucasBrazi06

+0

我更新了消息,所以你可以用我的真實數據;-) – LucasBrazi06

+0

我檢查看到。首先你確定這是工作'{type:String,ref:'ChargingStation'}'我剛剛看到一個對象id引用。那麼它不清楚'attributes'只意味着一個'Attribute'模式,還是它也是一個數組? –

相關問題