import mongoose from 'mongoose';
const { Schema } = mongoose;
const blogSchema = new Schema({
title: String, // String is shorthand for {type: String}
author: String,
body: String,
comments: [{ body: String, date: Date }],
Javascript
1
import mongoose from 'mongoose';
2
const { Schema } = mongoose;
3
date: { type: Date, default: Date.now },
hidden: Boolean,
meta: {
votes: Number,
favs: Number
}
});
//1st style
var mongoose = require('mongoose');
var Schemax = mongoose.Schema;
var blogSchema = new Schemax({
title: String, // String is shorthand for {type: String}
author: String,
body: String,
comments: [{ body: String, date: Date }],
date: { type: Date, default: Date.now },
hidden: Boolean,
meta: {
votes: Number,
favs: Number
}
});
module.exports = mongoose.model( 'model name' , blogSchema);
//2nd style
const mongoose = require('mongoose')
const Schema Name = mongoose.Schema({
name : {
type : String,
default : 'default txt',
},
})
module.exports = mongoose.model( 'model name' , Schema Name);
import mongoose from 'mongoose';
const { Schema } = mongoose;
const blogSchema = new Schema({
title: String, // String is shorthand for {type: String}
author: String,
body: String,
comments: [{ body: String, date: Date }],
date: { type: Date, default: Date.now },
hidden: Boolean,
meta: {
votes: Number,
favs: Number
}
});