-
Notifications
You must be signed in to change notification settings - Fork 2
/
upload.js
58 lines (41 loc) · 1.2 KB
/
upload.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
var Joi = require('joi');
var http = require('http');
var mongodb = require('mongodb');
//var collName = "posts";
var MongoClient = mongodb.MongoClient;
var dbAddy = "mongodb://neapolitan:[email protected]:10081/neapolitan1";
//var dbAddy = process.env.MONGOHQ_URL;
alert("HI I AM LOADED");
var entlanding;
var maxid = 0;
function getLowID() {
MongoClient.connect(dbAddy, function (err, db) {
var collection = db.collection('posts');
collection.find().sort({"id": -1}).limit(1).toArray(function (err, docs) {
maxid = docs[0].id;
console.log(docs[0].id);
maxid++;
});
});
}
var ear = document.getElementById('submitbutton');
ear.addEventListener("click", pushPost, false);
function pushPost(){
var newname = document.getElementById('author').value;
var newentry= document.getElementById('entry').value;
var newPost = {
id: maxid,
date: "22102014",
name: newname,
text: newentry
};
MongoClient.connect(dbAddy, function (err, db) {
var collection = db.collection('posts');
collection.insert(newEntry, function(err,data) {
if(err) console.log(err);
alert("uploaded");
pullPosts();
maxid++;
});
});
}