mongoose schema nested code example

Example 1: nested json schema mongoose

var mongoose =require('mongoose');
var Schema = mongoose.Schema;

var msg = new Schema({
  messageType: String,
  timestamp: Number,
  messagestatus: String
});

var standardmessage = new Schema({
  id: Number,
  name: String,
  type: String,
  message: [msg]
});

Example 2: mongoose nested require

var jobSchema = Schema({
  negotiation: { state: { type: String, required: hasNegotiation } }
});

function hasNegotiation() {
  return this.negotiation && Object.keys(this.negotiation).length > 0;
}

Example 3: nested json schema mongoose

var mongoose =require('mongoose');
var Schema = mongoose.Schema;

var standardmessage = new Schema({
  id: Number,
  name: String,
  type: String,
  message: {
    messageType: String,
    timestamp: Number,
    messagestatus: String
  }
});

Tags:

Misc Example