nestjs mongoose schema 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 schema
const mongoose = require('mongoose');
const UserSchema = new mongoose.Schema({
name: {
type: String,
required: true
}
}, {
timestamps: true
})
const User = mongoose.model('User', UserSchema);
module.exports = User;
Example 3: mongoose nestjs
$ npm install --save @nestjs/mongoose mongoose
Example 4: 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
}
});