 NO sql
 NO relational
 NO joins
 NO ORM
 NO complex transactions
   海量数据
   高并发
   高可用
   复杂度
   非结构化数据
   需求变化
   Data Model
     1,2,3范式
     tree、master/detail、relation…
   Objects != Data
     ORM
     DAL
   Key-value
     Memcached、Redis
   Graph Databases
     Neo4j
   Column Families
     BigTable,HBase,cassandra
   Document
     CouchDB,mongoDB
   酸 ACID
     atomicity, consistency, isolation, durability
   碱 BASE
     Basically Available, Soft-state, Eventually
     Consistent
 Consistency (一致性)
 Availability (可用性)
 Partition tolerance (分区容忍性)

一个分布式系统不可能同时满足这三个需求
   最多只能同时满足两个(AP/CP)
Memory is the new disk,
disk is the new tap
-Jim Gray
function map(fn, a){                 function reduce(fn, a, init){
   for (i = 0; i < a.length; i++){     var s = init;
     a[i] = fn(a[i]);                  for (i = 0; i < a.length; i++)
                                            s = fn( s, a[i] );
    }                                  return s;
}                                    }

(Joel on Software)
   NoSQL Databases: Why, what and when
   NoSQL生态系统
http://www.mongodb.org/
   Document-oriented
   Rich, document-based queries
   Full Index Support
   Replication & High Availability
   Sharding
   GridFS
   Map/Reduce
   BSON everywhere
   Memory Mapped Data Files
   http://try.mongodb.org/
   mongod
     mongodb.conf
   mongo
   mongos
   mongostat
   mongoexportmongoimport
   mongodumpmongorestore
   默认数据存储路径是 /data/db,
   默认端口 27017
   默认 HTTP 端口 28017
   日志
     --logpath、--logappend、--verbose、--cpu
   一个.ns文件和n个数据文件
   数据文件大小2倍倍增
   单数据文件最大2G
   显示创建
   不能删除对象
   方便传输
   高效
   通用




           http://bsonspec.org
   每个BSON对象大小不能超过4MB
   字段名不能以”$”开头;不能包含”.”
   “_id”是系统保留的字段
> help
   4e2647e8 0fe07f 1260 54caf4
     Timestamp + Machineid + Processid + Counter

一个对象被插入到数据库中时,如果它没有ID,会自动生
 成一个”_id”字段,为24位16进制数。
   <, <=, >, >=      Regular Expressions
   $all
   $exists           Embedded Object Search
   $mod              JavaScript Expressions
   $ne               Special operators
   $in
   $nin              Explain()
   $nor
   $or
   $and
   $size
   $type
   Count
     db.characters.find({armor:{$gt:1800}}).count()
   Limit
   Skip ()
     db.characters.find({armor:{$gt:1800}}).skip(10).limit(1)
   Sort
     db.characters.find().sort({armor:-1}).limit(3)
     db.characters.find().sort({$natural:-1}).
   B Tree,支持geospatial index
   影响写速度,占用空间
   默认索引:_id
   索引顺序影响是否用到索引
   索引中缺少的字段为null
   explain()查看执行计划
   索引保存在 system.indexes
   索引大小 db. characters.totalIndexSize()
   创建索引 db.characters.ensureIndex(key_pattern, options)
     选项: unique; dropDups ; background
   查看索引 db.characters.coll.getIndexes()
   删除索引 db.characters.dropIndexes()
   重建索引 db.characters.reIndex()
   Udate(criteria, objNew, upsert, multi)
   Save()
   支持原子操作tomic
   不支持传统事务模型(rollback??)
   findAndModify (<options> } )
     find, modify, and return
   db.colname’.remove({…})
   db.eval(…);
   http://localhost:28017/_commands
   db.runCommand( {
     <commandname>: <value> [, options] } );
   db.commandHelp("datasize")
   Http Console
     http://localhost:28017/
   mongostat
   db.serverStatus()
   db.stats()、db.colname.stats()
   db.colname.validate()
   系统监控
     memory、cpu、IO
   setProfilingLevel(lvl, <ms>)
     0: none
     1: time-based(默认100ms)
     2: all


   db.system.profile.find()
   mongod --repair
   db.repairDatabase();
   mongod --journal
     version 1.9.2+64-bit默认开启
     group commit
   db.colname.validate();
   Master
   Master/slave
     arbiterOnly
   Replica sets
     db.printReplicationInfo()
     db.printSalveReplicationInfo()
     oplog(capped collection,规划大小)
   Params
     w: number of replicas to write to
     wtimeout: time to wait for acknowledgements
     fsync: flush to disk
   Unique Index
   空间成本
   维护
   failover
   Single
   One – Many & Many - Many
     Embedded document(4M的限制)
     Normalized
   Tree
   Javascript执行性能
   db.addUser
    ("username", "password")
   db.system.users.remove
    ({user: username})
   system.namespaces
   system.indexes
   system.profile
   system.users
   local.sources
   --rest选项
   备份
     mongodump、mongorestore
     db.copyDatabase、db.cloneDatabase
   Lock, Snapshot and Unlock
     admin.runCommand({fsync : 1, lock : 1})
     db.$cmd.sys.unlock.findOne()
   缺少传统数据库丰富的还原机制
   队列
   执行计划
     db.colname.find({..}).expliain()
   减小json数据的大小(使用较短的key)
   优化索引、索引全部放入内存
   优化document schema设计
   db.eval() 在服务端执行某些操作
   用BinData存储UUID格式的数据
     36bytes->16bytes
   使用连接池,修改每个连接的stack size
     默认10M
   预分配空间、减少内存和磁盘碎片
     删除数据--不收回碎片
   NoSQL注入
   --auth 启动参数
   --noscripting启动参数
   每个链接一个线程
   单线程执行Map/Reduce
   一个写线程
   磁盘空间
   内存
   维护
   事务
   mongo-csharp-driver (Github)
   CSharp Driver Tutorial
   MongoDB Deployment Strategies
   MongoDB开发应用实践
   Optimizing MongoDB: Lessons Learned at
    Localytics
   Chrome扩展Mongo Live
   MongoDB部署与运维
   10 Key MongoDB Performance Indicators
   MongoDB Administration
Thanks
文中大部分资料来源于网络

MongoDB for C# developer

  • 2.
     NO sql NO relational  NO joins  NO ORM  NO complex transactions
  • 3.
    海量数据  高并发  高可用  复杂度  非结构化数据  需求变化
  • 5.
    Data Model  1,2,3范式  tree、master/detail、relation…  Objects != Data  ORM  DAL
  • 6.
    Key-value  Memcached、Redis  Graph Databases  Neo4j  Column Families  BigTable,HBase,cassandra  Document  CouchDB,mongoDB
  • 9.
    酸 ACID  atomicity, consistency, isolation, durability  碱 BASE  Basically Available, Soft-state, Eventually Consistent
  • 10.
     Consistency (一致性) Availability (可用性)  Partition tolerance (分区容忍性) 一个分布式系统不可能同时满足这三个需求 最多只能同时满足两个(AP/CP)
  • 12.
    Memory is thenew disk, disk is the new tap -Jim Gray
  • 15.
    function map(fn, a){ function reduce(fn, a, init){ for (i = 0; i < a.length; i++){ var s = init; a[i] = fn(a[i]); for (i = 0; i < a.length; i++) s = fn( s, a[i] ); } return s; } } (Joel on Software)
  • 17.
    NoSQL Databases: Why, what and when  NoSQL生态系统
  • 18.
  • 19.
    Document-oriented  Rich, document-based queries  Full Index Support  Replication & High Availability  Sharding  GridFS  Map/Reduce  BSON everywhere  Memory Mapped Data Files
  • 23.
    http://try.mongodb.org/
  • 24.
    mongod  mongodb.conf  mongo  mongos  mongostat  mongoexportmongoimport  mongodumpmongorestore
  • 25.
    默认数据存储路径是 /data/db,  默认端口 27017  默认 HTTP 端口 28017  日志  --logpath、--logappend、--verbose、--cpu
  • 26.
    一个.ns文件和n个数据文件  数据文件大小2倍倍增  单数据文件最大2G
  • 28.
    显示创建  不能删除对象
  • 29.
    方便传输  高效  通用 http://bsonspec.org
  • 30.
    每个BSON对象大小不能超过4MB  字段名不能以”$”开头;不能包含”.”  “_id”是系统保留的字段
  • 31.
  • 33.
    4e2647e8 0fe07f 1260 54caf4  Timestamp + Machineid + Processid + Counter 一个对象被插入到数据库中时,如果它没有ID,会自动生 成一个”_id”字段,为24位16进制数。
  • 35.
    <, <=, >, >=  Regular Expressions  $all  $exists  Embedded Object Search  $mod  JavaScript Expressions  $ne  Special operators  $in  $nin  Explain()  $nor  $or  $and  $size  $type
  • 38.
    Count  db.characters.find({armor:{$gt:1800}}).count()  Limit  Skip ()  db.characters.find({armor:{$gt:1800}}).skip(10).limit(1)  Sort  db.characters.find().sort({armor:-1}).limit(3)  db.characters.find().sort({$natural:-1}).
  • 39.
    B Tree,支持geospatial index  影响写速度,占用空间  默认索引:_id  索引顺序影响是否用到索引  索引中缺少的字段为null  explain()查看执行计划
  • 42.
    索引保存在 system.indexes  索引大小 db. characters.totalIndexSize()  创建索引 db.characters.ensureIndex(key_pattern, options)  选项: unique; dropDups ; background  查看索引 db.characters.coll.getIndexes()  删除索引 db.characters.dropIndexes()  重建索引 db.characters.reIndex()
  • 44.
    Udate(criteria, objNew, upsert, multi)  Save()  支持原子操作tomic  不支持传统事务模型(rollback??)
  • 46.
    findAndModify (<options> } )  find, modify, and return
  • 47.
    db.colname’.remove({…})
  • 48.
    db.eval(…);
  • 49.
    http://localhost:28017/_commands  db.runCommand( { <commandname>: <value> [, options] } );  db.commandHelp("datasize")
  • 51.
    Http Console  http://localhost:28017/  mongostat  db.serverStatus()  db.stats()、db.colname.stats()  db.colname.validate()  系统监控  memory、cpu、IO
  • 52.
    setProfilingLevel(lvl, <ms>)  0: none  1: time-based(默认100ms)  2: all  db.system.profile.find()
  • 53.
    mongod --repair  db.repairDatabase();  mongod --journal  version 1.9.2+64-bit默认开启  group commit  db.colname.validate();
  • 54.
    Master  Master/slave  arbiterOnly  Replica sets  db.printReplicationInfo()  db.printSalveReplicationInfo()  oplog(capped collection,规划大小)
  • 57.
    Params  w: number of replicas to write to  wtimeout: time to wait for acknowledgements  fsync: flush to disk
  • 58.
    Unique Index  空间成本  维护  failover
  • 59.
    Single  One – Many & Many - Many  Embedded document(4M的限制)  Normalized  Tree
  • 60.
    Javascript执行性能
  • 62.
    db.addUser ("username", "password")  db.system.users.remove ({user: username})
  • 63.
    system.namespaces  system.indexes  system.profile  system.users  local.sources
  • 64.
    --rest选项
  • 65.
    备份  mongodump、mongorestore  db.copyDatabase、db.cloneDatabase  Lock, Snapshot and Unlock admin.runCommand({fsync : 1, lock : 1}) db.$cmd.sys.unlock.findOne()  缺少传统数据库丰富的还原机制  队列
  • 66.
    执行计划  db.colname.find({..}).expliain()  减小json数据的大小(使用较短的key)  优化索引、索引全部放入内存  优化document schema设计  db.eval() 在服务端执行某些操作  用BinData存储UUID格式的数据  36bytes->16bytes  使用连接池,修改每个连接的stack size  默认10M  预分配空间、减少内存和磁盘碎片  删除数据--不收回碎片
  • 67.
    NoSQL注入  --auth 启动参数  --noscripting启动参数
  • 68.
    每个链接一个线程  单线程执行Map/Reduce  一个写线程
  • 69.
    磁盘空间  内存  维护  事务
  • 70.
    mongo-csharp-driver (Github)  CSharp Driver Tutorial
  • 71.
    MongoDB Deployment Strategies  MongoDB开发应用实践  Optimizing MongoDB: Lessons Learned at Localytics  Chrome扩展Mongo Live  MongoDB部署与运维  10 Key MongoDB Performance Indicators  MongoDB Administration
  • 74.