0

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]
   });
3
  • Have you tried defining a nested type as described here: stackoverflow.com/a/14164860/1567923 ? Commented Apr 28, 2017 at 10:15
  • yes , see my update 1 .. no change Commented Apr 28, 2017 at 11:06
  • see my answer , sorry forgot to load the lines data .. so the output was empty.. your feedback is right , using a nested type as stated in my update runs well.. Commented Apr 28, 2017 at 16:31

1 Answer 1

0

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

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.