forked from cheekujodhpur/ipho2015
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsave_mark.txt
47 lines (45 loc) · 1.56 KB
/
save_mark.txt
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
app.post('/save_mark_T1',function(req,res){
var jsonString = '';
req.on('data',function(data)
{
jsonString += data;
})
req.on('end',function(){
var jsonData = JSON.parse('{"' + decodeURI(jsonString).replace(/"/g, '\\"').replace(/&/g, '","').replace(/=/g,'":"') + '"}');
var dbData = [];
var country_name = '';
for(var i in jsonData)
{
if(i!='country')
dbData.push(parseFloat(jsonData[i]));
else country_name = jsonData[i];
}
MongoClient.connect("mongodb://localhost:27017/test",function(err,db)
{
if(err)
{
console.log(err);
return 0;
}
if(req.ip != null)
{
var ip = req.ip.toString();
}
else
{
console.log("Null IP Error.Carry on");
return;
}
console.log("Connection established to the server at mongodb://localhost:27017/test in response to " + ip.toString());
if(country_name=='')
var marks = db.collection('marks_T1');
else var marks = db.collection('ourMarks_T1');
var query_ob = {};
if(country_name=='')query_ob["ip"] = ip;
else query_ob["country_name"] = country_name;
marks.update(query_ob,{$set:{"leaderMarks":dbData}},{upsert:true},function(err,result){
res.json({"success":true});
db.close();});
});
});
});