More Related Content
Similar to MongoDB + node.js で作るソーシャルゲーム (20)
MongoDB + node.js で作るソーシャルゲーム
- 9. Mongo Tokyo 2011 - node.js + MongoDB
HTTP
WebSocket
Client (Flash) LB
node.js
3x3 Sharding
MongoDB
Content
SVN or git Distribution
- 11. Mongo Tokyo 2011 - node.js + MongoDB
var entity = {
_id: ‘abc’,
name: ‘test’,
body: {
parts: {
face: 0, eye: 2, nose: 4, mouth: 2
},
colors: {
skin: 1, eye: 4, hair: 3
}
}
};
col.save(entity);
col.findOne({_id:‘abc’}, function(err, result) {
console.log(result.body.parts);
});
col.update({_id:‘abc’},
{‘$set’, {name: ‘modified’}}
);
- 12. Mongo Tokyo 2011 - node.js + MongoDB
https://github.com/orlandov/node-mongodb/
https://github.com/christkv/node-mongodb-native/
- 14. Mongo Tokyo 2011 - node.js + MongoDB
var client = new Db('test', new Server("127.0.0.1", 27017, {}));
client.open(function(err, p_client) {
client.createCollection('test_insert',function(err, collection) {
client.collection('test_insert', function(err, collection) {
for(var i = 1; i < 1000; i++) {
collection.insert({c:1}, function(err, docs) {});
}
collection.insert({a:2}, function(err, docs) {
collection.insert({a:3}, function(err, docs) {
collection.count(function(err, count) {
test.assertEquals(1001, count);
collection.find(function(err, cursor) {
cursor.toArray(function(err, results) {
test.assertEquals(1001, results.length);
test.assertTrue(results[0] != null);
client.close();
});
});
});
});
});
});
});
});
- 16. Mongo Tokyo 2011 - node.js + MongoDB
var db = new Database(‘127.0.0.1’, 3306, ‘test’);
db.open();
var item = db.collection(‘item’);
item
.begin()
.insert({_id:‘test’, name:‘abcdefg’})
.insert({_id:‘test2’, name:‘123456’, values:[0,1,2,3]);
.update({_id:‘test’}, {‘$set’: { name: ‘hijklmn’ })
.find({}).each(function(entity) {
console.log(entity.name);
})
.success(function() {
console.log(‘done’);
})
.failure(function(err) {
console.log(‘error’, err);
})
.end();
- 21. Mongo Tokyo 2011 - node.js + MongoDB
var spec1 = {
name: ‘test’,
type: ‘text’,
label: ‘label-1’,
class: ‘number’,
min: 0, max: 100
};
var spec2 = {
name: ‘test2’,
type: ‘group’,
label: ‘group-1’,
fields: [spec3, spec4, spec5]
};
var formSpec = [
spec1, spec2
];
showForm(formSpec);
- 24. Mongo Tokyo 2011 - node.js + MongoDB
{ "_id" : "plant_ichigo",
"name" : " ",
"type" : "plant",
"plant" : {
"tags" : [ "vegetable" ],
"time" : { "grow" : 10, "expire" : 60 },
"rewards" : [
! {
! ! "type" : "coin",
! ! "rate" : 1,
! ! "min" : 5,
! ! "max" : 20,
! ! "code" : ""
! },
! {
! ! "type" : "exp",
! ! "rate" : 1,
! ! "min" : 1,
! ! "max" : 2,
! ! "code" : ""
! },
! {
! ! "type" : "item",
! ! "rate" : 1,
! ! "min" : 1,
! ! "max" : 1,
! ! "code" : "material_ichigo"
! }
]}