-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathdata.js
35 lines (31 loc) · 867 Bytes
/
data.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
module.exports = {
func: function() {
mongo.connect(DBURL,function(err,db){
if (err){
console.log("Failed to connect to the database.");
res.sendStatus(500);
db.close();
}else{
db.collection("files").find({},{_id:1,name: 1, data:0},function(err,cursor){
if(err){
res.sendStatus(500);
}else{
var fileList = [];
cursor.each(function(err,doc){
if(err){
res.sendStatus(500);
}else if (doc === null){
res.send({files:fileList}); //sending an object with the form {files: [name1, name2, ...]}
db.close();
}else{
fileList.push([doc.name,doc._id]);
}
})
}
});
}
});
},
getData: function(id){
},
};