Creating our model
CHAT.JS
it is exported to index.js
const mongoose = require("mongoose");
const chatSchema = new mongoose.Schema({
from: {
type: String,
required: true,
},
to: {
type: String,
required: true,
},
msg: {
type: String,
maxLength: 50,
},
created_at: {
type: Date,
required: true,
},
});
const Chat=mongoose.model("Chat",chatSchema);
module.exports=Chat;
index.js
const Chat = require("./models/chat.js");
let chat1 = new Chat({
from: "abhi",
to: "ash",
msg: "silencer",
created_at: new Date(),
});
chat1
.save()
.then((res) => {
console.log(res);
})
.catch((err) => {
console.log(err);
});
Comments
Post a Comment