简体   繁体   English

猫鼬模式,如何定义一个Array of Array对象

[英]Mongoose schema , how to define an Array of Array object

Is the following Mongoose schema correct ? 以下猫鼬模式正确吗?

const TableSchema = new mongoose.Schema({
  meta: {... },
  columns: [{...}],
  lines: [[Schema.Types.Mixed]]
});

using the following table 使用下表

  let table1 = {
    meta: { ... },
    columns: [ { ... }, { ... } ],
    lines: [[12, 'Joe'], [14, 'John'], [6, 'Walter'], [3, 'William'], [18, 'Bill'], [22, 'Albert']]
  };

when I get and display the table, the lines array is empty : 当我获取并显示表格时,lines数组为空:

table:  { 
_id: 5903113e80587e09bf39be34,
  __v: 0,
  lines: [],
  columns: 
   [ { _id: 5903113e80587e09bf39be36, ... },
     { _id: 5903113e80587e09bf39be35, ... } ],
  meta: 
   { name: 'TA-PRIV-123', ... }
}

UPDATE 1 更新1

I also tried 我也试过

   const Line = new mongoose.Schema([Schema.Types.Mixed]);
   const TableSchema = new mongoose.Schema({
     ...
     lines: [Line]
   });

solved 解决了

I forgot to add the lines in the previous POST request so the lines field was empty.. so Maxime feedback is right.. and my UPDATE 1 runs well 我忘了在上一个POST请求中添加行,因此lines字段为空..因此Maxime反馈是正确的..并且我的UPDATE 1运行良好

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM