//先包含进来 var MongoDB = require('./mongodb'); //查询一条数据 MongoDB.findOne('user_info', {_id: user_id}, function (err, res) { console.log(res); }); //查询多条数据 MongoDB.find('user_info', {type: 1}, {}, function (err, res) { console.log(res); }); //更新数据并返回结果集合 MongoDB.updateData('user_info', {_id: user_info._id}, {$set: update_data}, function(err, user_info) { callback(null, user_info); }); //删除数据 MongoDB.remove('user_data', {user_id: 1});
就先举这些例子,更多的可亲自尝试吧!
其中配置中的 config/table.json 是数据库集合的配置项,结构如下:
{ "user_stats_data": { "user_id": "Number", "platform": "Number", "user_first_time": "Number", "create_time": "Number" }, "room_data": { "room_id": "String", "room_type": "Number", "user_id": "Number", "player_num": "Number", "diamond_num": "Number", "normal_settle": "Number", "single_settle": "Number", "create_time": "Number" }, "online_data": { "server_id": "String", "pf": "Number", "player_num": "Number", "room_list": "String", "update_time": "Number" } }
记得每次给添加字段时,要往这个table.json里面添加。由于nodejs这个服务器的改动,更改table.json往往需要重启游戏服务的。