MemDB 是全球首个支持分布式事务的 MongoDB。
快速的内存数据访问,高达 25,000 ops (single doc read/write) /碎片 (each shard take one CPU core).
系统可水平伸缩
没有单点瓶颈
在分布式环境真正支持 ACID (Stands for Atomicity, Consistency, Isolation, Durability) 事务
MemDB 让 MongoDB 支持 ACID 事务
直接使用 MongoDB 的查询 API
内置 Mongoose 支持
MemDB shell:
架构:
Mdbgoose:
var memdb = require('memdb-client'); var P = memdb.Promise; var mdbgoose = memdb.goose; // Define player schema var playerSchema = new mdbgoose.Schema({ _id : String, name : String, areaId : Number, deviceType : Number, deviceId : String, items : [mdbgoose.SchemaTypes.Mixed], }, {collection : 'player'}); // Define player model var Player = mdbgoose.model('player', playerSchema); var main = P.coroutine(function*(){ // Connect to memdb yield mdbgoose.connectAsync({ shards : { // specify all shards here s1 : {host : '127.0.0.1', port: 31017}, s2 : {host : '127.0.0.1', port: 31018}, } }); // Make a transaction in s1 yield mdbgoose.transactionAsync(P.coroutine(function*(){ var player = new Player({ _id : 'p1', name: 'rain', areaId : 1, deviceType : 1, deviceId : 'id1', items : [], }); // insert a player yield player.saveAsync(); // find player by id var doc = yield Player.findByIdAsync('p1'); console.log('%j', doc); // find player by areaId, return array of players var docs = yield Player.findAsync({areaId : 1}); console.log('%j', docs); // find player by deviceType and deviceId player = yield Player.findOneAsync({deviceType : 1, deviceId : 'id1'}); // update player player.areaId = 2; yield player.saveAsync(); // remove the player yield player.removeAsync(); }), 's1'); }); if (require.main === module) { main().finally(process.exit); }