【问题标题】:MongoDB - NodeJs - Maximum call stack size exceededMongoDB - NodeJs - 超出最大调用堆栈大小
【发布时间】:2017-09-02 04:39:03
【问题描述】:

在 MongoDB/NodeJs(使用 Mongoose)中保存以下架构时出现此错误: 未捕获的 RangeError:超出最大调用堆栈大小。

当我在数组中的架构中添加详细信息时会发生这种情况:

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]
});

有什么想法吗?

提前致谢! 塞尔吉。

【问题讨论】:

    标签: node.js mongodb mongoose


    【解决方案1】:

    我认为您必须为数组中的模型定义一个额外的架构。

    类似:

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

    【讨论】:

    • 非常感谢,但我也试过这个没有成功:(
    • 我更新了消息,以便您查看我的真实数据;-)
    • 我明白了。首先,您确定这是有效的 {type: String, ref: 'ChargingStation'} 我刚刚看到带有对象 ID 引用。那么不清楚attributes 是指一个Attribute 模式还是它也是一个数组?
    • 是的,我将充电站的 _id 更改为字符串,因为它的名称是唯一的,比在其他模式中更容易识别。这只是一个属性;我同意它与“属性”名称混淆。
    猜你喜欢
    • 1970-01-01
    • 2019-07-05
    • 2014-02-07
    • 2017-07-02
    • 1970-01-01
    • 2020-04-14
    • 1970-01-01
    • 2018-06-26
    • 2020-11-16
    相关资源
    最近更新 更多