-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathplayground-2.js
54 lines (38 loc) · 1.13 KB
/
playground-2.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
var mongoose = require("mongoose")
var {careSetting, careDaily, careWeekly} = require("./mongoose-schemas/one")
mongoose.connect("mongodb://localhost:27017/test", { useNewUrlParser: true })
// Get Mongoose to use the global promise library
mongoose.Promise = global.Promise;
//Get the default connection
var db = mongoose.connection;
//Bind connection to error event (to get notification of connection errors)
db.on('error', console.error.bind(console, 'MongoDB connection error:'));
var moment = require("moment")
moment().format()
careDaily.findOne({sender_PSID: "9000"}).then((doc) => {
return doc
},(e) => {
console.log(e)
}).then((doc) => {
var found = doc.myDayDetails.find(function(ele){
return ele.day_of_year === moment().dayOfYear()
})
if(!found){
doc.myDayDetails.push({
"day_of_year" : moment().dayOfYear(),
"daily_goals" : "LOSER"
})
}else{
found.daily_goals = "LOSER"
}
doc.save().then((doc) => {
console.log("success")
}, (e) => {
console.log(e)
})
}, (e) =>{
console.log(e)
})
module.exports = {
mongoose
}