简体   繁体   中英

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 :

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

UPDATE 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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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