-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsave_message.js
110 lines (82 loc) · 2.48 KB
/
save_message.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
/*
require('dotenv').config();
// const { json } = require("express");
const mongoose = require("mongoose");
const validator = require("validator");
let link = process.env.DB_LINK;
var json_data;
var document;
var model;
function connect_to_db() {
mongoose.connect(link, { useNewUrlParser: true, useUnifiedTopology: true, useCreateIndex: true }).catch(error => { });
}
var profile_schema = new mongoose.Schema({
friend_name: String,
friend_email: String,
chat_message: [] ,
recieve_message:[],
is_blocked:Boolean
});
function create_model() {
model = mongoose.model(json_data.name,profile_schema);
model.findOne({friend_name:json_data.name},function (err,data) {
if(err){
// pr("error occurs ",err);
return err
}
else{
if(!data){
document = new model ({friend_name : "admin",friend_email: "[email protected]" ,recieve_message:["welcome to this chat app"]});
document.save((err,doc)=>{
if(err){
pr("errori s: ",err);
}
else{
pr("succes full saved the first documetn " );
}
});
}
else{
pr("user already present ");
}
}
})
}
// pr("document is; ",document);
// document.save();
async function save_message () {
var result;
pr("json_data is: ",json_data);
// var obj = {friend}
// pr("model is: ",model );
// document = new model({
// name: json_data.sender_name,
// email: "m
// },
// chat_message: ["this is first saved message ","this is second saved message " ] ,
// recieve_message:["this is first recievced message "],
// });
// result = await document.save()
// pr("resul its; ",result);
result = await model.updateOne({friend_name:json_data.sender_name},{$push:{recieve_message:"this is message" }});
// pr("result is: ",result);
}
*/
async function main() {
// connect_to_db();
// let result;
// let data = {
// name:"mohan",
// sender_name:"maggi",
// sender_email: "[email protected]",
// reciver_email: "[email protected]",
// sender_message: "this is sample message ",
// time:"10:20pm"
// }
// json_data = data;
// create_model();
// await save_message();
// // mongoose.connection.close();
// return result;
}
main();