-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.js
More file actions
53 lines (37 loc) · 1.01 KB
/
server.js
File metadata and controls
53 lines (37 loc) · 1.01 KB
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
var mongo = require('mongodb').MongoClient,
client = require('socket.io').listen(8080).sockets,
fs = require('fs');
mongo.connect('mongodb://127.0.0.1/database',function(err,db) {
if(err){ console.log(err); throw err; };
client.on('connection',function(socket){
/* User connects with socket.id */
console.log("User connects with socket id " + socket.id);
/* On request */
socket.on('request', function(data){
var collection = db.collection(data.collection);
if(data.type == 'get'){
get(collection, data);
}
if(data.type == 'insert'){
}
if(data.type == 'update'){
}
if(data.type == 'delete'){
}
});
/* On socket disconnect */
socket.on('disconnect', function (data) {
console.log('User disconnects: ' + socket.id);
});
});
});
function get(collection, data){
collection.find(data.query);
}
console.log('Server started successfully.');
// Example query
var query = {
type : 'get',
collection: 'mycollection',
query: "{ score: { $gt: 0, $lt: 2 } }"
};