View difference between Paste ID: Q95beYFh and qWcAFpy1
SHOW: | | - or go back to the newest paste.
1
var express = require('express')
2
  , http = require('http') , path = require('path');
3
4
var app = express();
5
6
// all environments
7
app.set('port', process.env.PORT || 5000);
8
app.set('views', __dirname + '/views');
9
app.set('view engine', 'jade');
10
app.use(express.favicon());
11
app.use(express.logger('dev'));
12
app.use(express.bodyParser());
13
app.use(express.methodOverride());
14
app.use(app.router);
15
app.use(express.static(path.join(__dirname, 'public')));
16
17
// development only
18
if ('development' == app.get('env'))
19
{
20
  app.use(express.errorHandler());
21
}
22
23
// Connect DB
24
var dbName = 'MasterData';
25
var collections = ['games'];
26
27
var db = require('mongojs').connect(dbName, collections);
28
29
// Setup Routes
30
app.get('/', function(req, res) 
31
{
32
    res.render('index', {title: "TATA"});
33
});
34
35
app.get('/games', function(req, res) {
36
	res.send('Welcome to Games!');
37
});
38
39
app.get('/games/:id', function(req, res) {
40
    var id = req.params.id;
41
    db.games.find({ "_id" : db.ObjectId(id) }, function(err, games) {
42
        if (err) { throw err }
43
        res.json(games);
44
    });
45
});
46
47
// POST
48
app.post('/games', function(req, res) {
49
    res.json(req.body);
50
    db.games.save(req.body);
51
    });
52
53
54
55
56
http.createServer(app).listen(app.get('port'), function(){
57
  console.log('Express server listening on port ' + app.get('port'));
58
});
59
60
61
the json that i stored in MasterData db using games collection is
62
63
64
[
65
    {
66-
    "0": {
66+
      "_id":" 1234",
67-
      "id":" 1234",
67+
68
      "name": "mark",
69
      "gameid": "123456789098g123",
70
      "os": "Ipad"
71
     },
72-
    },
72+
73-
    "1": {
73+
   {
74-
      "id":" 5678",
74+
      "_id":" 5678",
75-
      "appid": " 43215678909h1230",
75+
76-
      "name": "james",
76+
77
      "gameid": "123456789098g123",
78
      "os": "Ipad"
79-
    },
79+
     },
80-
    "2": {
80+
81-
      "id":" 9011",
81+
   {
82-
      "appid": " 98015678909h1230",
82+
      "_id":" 9011",
83-
      "name": "amgela",
83+
84
      "name": "mark",
85
      "gameid": "123456789098g123",
86-
    },
86+
87-
    "3": {
87+
     },
88-
      "id":" 1213",
88+
89-
      "appid": " 45675678909h1230",
89+
90-
      "name": "gimmy",
90+
      "_id":" 1213",
91
      "appid": " 12345678909h1230",
92
      "name": "mark",
93-
    },
93+
94-
    "4": {
94+
95-
       "id":" 1415",
95+
     },
96-
      "appid": " 00985678909h1230",
96+
97-
      "name": "jaine",
97+
98
      "_id":" 1415",
99
      "appid": " 12345678909h1230",
100-
    },
100+
101-
    "_id": "52e0c7ade4b099eb8ffc8487"
101+
102-
  }
102+
103
     }
104
]