Use ‘type’ as a Property Name in a Mongoose Doc

less than 1 minute read

Jump in!

This will not work.

var contractSchema = new mongoose.Schema({
  questions: [{
    type: {type: 'string'},
    question: 'string'
  }],
  version: String,
  state: String
});

This will work.

var contractSchema = new mongoose.Schema({
  questions: [{
    type: 'string'
    question: 'string'
  }],
  version: String,
  state: String
});

Glad that’s settled :)