Node.js 操作Mongodb澳门美高梅手机网站

      db.collection.stats() provides statistics that resemble dbStats on
the collection level
      db.collection.stats() 再次回到当前集结的情况
   
      rs.status() returns an overview of your replica sets status
      rs.status() 重返集群的景况

娱乐销量方面,《生化危害7》、《怪物猎人XX》五款紧要大作销量表现尚可,但《生化危害4/5/6》五款重制文章在主机平台也收获了很大成功。但是二零一八年5月贩卖并登陆Xbox
One与PC平台的《丧尸围城4》表现糟糕,未完毕卡普空预期中的200万套出货量。

Back Up with Filesystem Snapshots   文件快照备份
You can create a backup of a MongoDB deployment by making a copy of
MongoDB’s underlying data files.   直接复制数据文件
文本快照须要 To get a correct snapshot of a running mongod process, you
must have journaling enabled  必须打开journaling
手续 1 db.fsyncLock() //上同步锁
     2 复制数据文件
     3 db.fsyncUnLock() //解锁
  
      Back Up with mongodump  使用 mongodump举办备份
适合单机,集群备份请使用专业工具
      simple and efficient tools for backing up and restoring small
MongoDB deployments, but are not ideal for capturing backups of larger
systems.  快速有效的备份,但不适应大批量数据的备份
      mongodump only captures the documents in the database
注意,mongodump只备份文档,对于索引等其他的是不备份的。
      步骤 mongodump –collection myCollection –db test  –out
/backup/dir
      具体参数请自行查看 mongodump –help
      苏醒备份 mongorestore   <path to backup>
7.运作景况
mongostat captures and returns the counts of database operations by
type
mongostat 突显操作(增删改查)的次数

我们好!《荣耀战魂》更新内容专业放出;《铁拳7》制作人访谈中大爆料;卡普空财报发布,《生化风险》冷饭大赚一波;《仁王》确认“东南之龙”DLC发售日。当然,最重点的是杉果家夏天打折起首,《生化风险7》、《辐射4》迎来史低价啦~

2.Map-Reduce
 Map-reduce is a data processing paradigm for condensing large volumes
of data into useful aggregated results
几乎意思是Map-reduce能对命局据量举办拍卖,并重返处理的结果
db.collection.mapReduce(
             function(){             
emite(this.x,this.z);        //map
},
             function(key,values){
                return Array.sum(values);   //reduce
},
             {
               query:{y:”b”},             //query
               out:”test”                //output to collection name
test
             }
)
6.数据模型
单文档操作是原子性的,扶助工作
多文档操作是出现的,不扶助工作
安装文档验证模型
db.createCollection(“contacts”,
  {  validator:{[
      {phone:{$type:”string”}},
      {email:{$regex:/@qq.com$/}}
     ]}
})
db.runCommand(
  {
    collMod:”contacts”,
    validator:{[
         {phone:{$type:”string”}},
         {email:{$regex:/@qq.com$/}}
       ]}
      validationLevel:”moderate”
  }
)
You cannot specify a validator for collections in the admin, local, and
config databases.
留神:您无法对admin,local,config数据库使用文档验证模型
7.管理
1.多线程
mmapv1 provides collection-level locking  
情趣是同一时间对collection里边的document操作只可以有唯一一个读或写
wiredTiger supports concurrent access by readers and writers to the
documents in a collection. Clients can read documents while write
operations are in progress, and multiple threads can modify different
documents in a collection at the same time
意思是wiredTiger协理同时对某一文档举行读写,同时对某一集合下的例外文档进行修改,说白了就是wiredTiger是document-level
locking 且读写对document可同时存在.
2.数目持久化
MongoDB uses write ahead logging to an on-disk journal. Journaling
guarantees that MongoDB can quickly recover write operations that were
written to the journal but not written to data files in cases where
mongod terminated due to a crash or other serious failure.
Mongodb 使用wal日志(写以前先记下到日志中)来保管高速恢复生机。
3.硬件须要
wiredTiger更多的cpu主题越好,最少2核心.
Mongodb3.2暗中认同使用四分之一的内存,且最小1GB,推荐是单机内存10G
运转时可以透过mongod –wiredTigerCacheSizeGB=xxx 来安装使用多少内存
wiredTigerCacheSizeGB: Defines the maximum size of the internal cache
that WiredTiger will use for all data.

除此以外,即便你还在犹豫购买是不是要选购游戏,也得以到杉果商城转转,进入活动页即可领取福袋,有着欧皇血统的玩家有只怕一贯获取《狙击手:幽灵战士3》与《战锤40k:战争黎明(英文名:lí míng)3》五款目前刚好出售的游戏啊~

MMAPv1 is the original MongoDB storage engine and is the default storage
engine for MongoDB versions before 3.2. It performs well on workloads
with high volumes of reads and writes, as well as in-place updates.
Mmapv1引擎在广大高并发读写方面,品质更好
但照旧不提出使用,它的故障復苏成效较弱,只有经过日记和备份苏醒。利用多核CPU方面也做的不佳。

生化风险7》与《丧尸围城4》均在杉果夏季优惠的限时折扣中以折扣价出售,《生化危害7》更是会创制新史低价格,感兴趣的玩家请别错过购买机会啊~

添加arbiter节点
rs.addArb(“m1.example.net:30000”)

3.卡普空财报展现集团收益上涨,《生化风险》冷饭成最大功臣。

Sharp key 限制
You cannot select a different shard key for that collection.
比方选定sharp key就无法再变动
You cannot update the values of the shard key fields.
不允许更新sharp key
You cannot shard a collection that has unique indexes on other fields.
有除sharp key列外别的列的绝无仅有索引的成团不只怕分片
You cannot create unique indexes on other fields for a sharded
collection
分片集群无法成立其余列的唯一索引

4.《仁王》“东南之龙”DLC发售日确定

集群的时候要保障时间共同(NTP)
4.质量优化
For read-heavy applications, increase the size of your replica set and
distribute read operations to secondary members.

《铁拳7》制作人原田胜弘近年来收受了征集,表露了娱乐的很多细节。

稀疏索引
Sparse indexes only contain entries for documents that have the indexed
field, even if the index field contains a null value
稀疏索引只索引包涵该索引列的文档,注意document的格式是不稳定的。
db.addresses.createIndex( { “xmpp_id”: 1 }, { sparse: true } )

但是,依据分析师提供的音信,《生化风险7》《怪物猎人XX》与《丧尸围城4》的销量全部未达预期,卡普空二零一九年的进项上升最大功臣可能是《生化风险》的冷饭……

The In-Memory Storage Engine is available in MongoDB Enterprise. Rather
than storing documents on-disk, it retains them in-memory for more
predictable data latencies.
In-Memory引擎唯有公司版才有,使用内存,速度更快,单对内存要求很高。

好评A奔驰G级PG游戏《仁王》的DLC“西南之龙”确认将于三月2日发售,新的守护灵、盔甲、忍术、阴阳术和新武器项目“大太刀”将会出席游戏。

     sh.shardCollection( “database.collection”, { <field> :
“hashed” } ) 创建hash sharp key

光荣战魂》将在杉果秋日降价时期以161元的史低价格售卖,感兴趣的玩家别错过哦~

9.存贮引擎
WiredTiger is the default storage engine starting in MongoDB 3.2. It is
well-suited for most workloads and is recommended for new deployments.
WiredTiger provides a document-level concurrency model, checkpointing,
and compression, among other features. In MongoDB Enterprise, WiredTiger
also supports Encryption at Rest.
多数景况下使用wiredTiger引擎有更好的显现,而且它帮助文档锁(document-level)

与DLC同时推出的还有PvP格局,拥有PS
Plus会员资格的玩家可以进行线上迎阵了,该方式将免费向装有《仁王》玩家开放。

Text索引  尽量不要接纳,很耗时耗内存 
db.reviews.createIndex( { comments: “text” } )
db.reviews.createIndex( { title:”text”,comments: “text” } ) //复合索引
db.reviews.createIndex( { title:”text”,comments: “text”
},{weight:{title:2,comments:5}} ) 权重
db.collection.dropIndex()   //删除索引
db.collection.getIndexes()  //获取索引

《铁拳7》将在11月2日登陆PS4、Xbox
One与PC平台,Steam国区普通版贩卖价格308元。至于杉果会以什么样的价钱销售,各位可以期待一下。

复合索引  db.collection.createIndex( { <field1>: <type>,
<field2>: <type2>, … } )
There can be no more than 31 fields in a compound index
复合索引不一致意当先31个复合列,item和stock无法同时为数组
举例表达: db.products.createIndex( { “item”: 1, “stock”: 1 } )
The index will contain references to documents sorted first by the
values of the item field and, within each value of the item field,
sorted by values of the stock field
率先先按item排序,每种item内部再按stock排序

5.杉果夏天优惠前几天中午12点起头!

留意,官网如是说
When building an index on a collection, the database that holds the
collection is unavailable for read or write operations until the index
build completes
确立目录的时候,mongodb不容许读写直到索引达成。除非加上参数backgroup:true
For replica sets, secondaries will begin building indexes after the
primary finishes building the index. In sharded clusters, the mongos
will send createIndex() to the primary members of the replica set for
each shard, which then replicate to the secondaries after the primary
finishes building the index.
Replica建立目录的时候,主节点先建索引,达成后,子节点在建立目录。
在Sharded(分片)集群中,主节点的一一分片先创建目录,完结后,轮到子节点各样分片Ensure
that your oplog is large enough to permit the indexing or re-indexing
operation to complete without falling too far behind to catch up
集群建立目录的时候,要安装充足大的oplog,否则会报错。
查阅索引品质 report使用zipcode索引的个性
db.people.find(
 { name: “John Doe”, zipcode: { $gt: “63000” } }
).hint( { zipcode: 1 } ).explain(“executionStats”)

2.《铁拳7》制作人访谈音信大汇总

chunks stores the binary chunks.  chunks集合存贮文件的二进制块
files stores the file’s metadata.    files集合存贮文件的叙述音信

至于《铁拳7》是或不是会登陆Switch的题材,原田胜弘则意味近年来三阳台版本《铁拳7》的创建已经让祥和毫无办法,甚至到方今甘休他都不曾机会亲自买到一台Switch,所以本作暂时不会登陆任天堂的新主机平台。

                               Hash sharp key

《街霸5》传说情势的缺失让许多玩家失去了买卖兴趣,不过《铁拳7》将装有一个情节充足的传说形式。该格局不断蕴含格斗迎战,甚至会有一对第两个人称射击与QTE成分存在,尽只怕抬高游戏的单机体验。

You cannot change the shard key after sharding, nor can you unshard a
sharded collection
小心:以key=x分片之后就无法在修改为key=y了,集群分片之后也无力回天还原为未分片前的情事了。

1.《荣耀战魂》第二赛季内容公布

  Master-Slave  
主从集群,操作简捷,没有故障自动回复法力,不做紧要讲解
mongod –master –dbpath /data/masterdb/ –oplogSize 1024   启动master
mongod –slave –source <masterhostname><:<port>>
–dbpath /data/slavedb/  启动slave
注意,日志一定要丰裕大,原因在于,master节点接受写须求,数据同时记录到日志中,然后,master节点把日记分发给各样slave节点,slave节点执行日志的始末,以达到数据同步。一旦大规模写,而日志容积太小就有或许造成,主从不一致步,数据不均等的情景。
rs.printReplicationInfo(),rs.printSlaveReplicationInfo() 
查看主节点状态,从节点状态
更加多措施请参见https://docs.mongodb.com/manual/reference/replication/

而在事后几天的限时折扣中,还有49元的《摧毁战士》、67元的《耻辱2》、66元的《街霸5》、120元的《漆黑之魂3》,育碧现年的六款新作《光荣战魂》和《幽灵行动:荒野》则均贩卖价格161元,别忘了把他们进入愿望单哦~

In production environments, individual shards should be deployed as
replica sets
Mongodb3.2版本提供shard的replica,在商用上,应该设置分片的备份。

率先,他发挥了梦想《铁拳7》可以落成PS4、Xbox
One跨平台联手的意思,但当下微软与索尼(Sony)的云浮政策让这一切很难落成,集团正在为此进行努力。

                   Node.js 操作Mongodb
1.简介
官网英文文档  https://docs.mongodb.com/manual/  这里大概什么都有了
MongoDB is open-source document database that provides high performance
, high availability , and automatic scaling.
MongoDB是一个开源的文档数据库,提供高质量、高可用性、自动缩放
2.安装
详尽的设置相关音信,比如帮助什么系统,32位和64位有哪些分裂,那么些请上官网自行查看

至于“杉果游戏”:一家为国内单机玩家操碎了心的游乐代理发行平台。已与B社、卡普空、华纳、万代南梦宫等70余家中外厂商建立合营,致力于将生化危害、上古卷轴、辐射、蝙蝠侠、乌黑之魂等单机游戏带给中华玩家。

分片策略    优点                     缺点                   适用
  Hash      数据均匀分布             顺序查询慢             基本适用
  Range     可针对某个阶段分片       数据不难并发头重脚轻   按等级查询

卡普空公开了卖家上一财年的财报,财报突显公司收益相比较二〇一八年上涨了13.2%,达到871.7亿加元,网络销售收入上升14.6%,达到88亿英镑。

3.命令
启动mongodb命令
cd mongodbHome
./bin/mongo   具体参数可以用 ./bin/mongo –help查看 如下
help          彰显辅助
show dbs      突显数据库列表
use <db>      转到某个数据库
show collections  展现当前数据库所含有的集纳(类似mysql中的表)
show users     展现当前数据库的用户列表
……           …….
……           …….
再有为数不少功能,那里就不列
4.增删改查
1.新增
db.collection.insert({x:”a”,y:”b”,z:”c”})
意思是向collection集合中插入一条数据,格式是x:”a”,y:”b”,z:”c” 
这几个格式类似json,可以自定义,collection是集聚名称,比如向user集合中插入数据{name=”老王”,info=”老王是一种神秘的生物体,他频仍就住在你隔壁”}可以那样写
db.user.insert({name:”老王”,info:”老王是一种神秘的浮游生物,他屡屡就住在你隔壁”})
mongodb3.2版还增添了
db.collection.insertOne()和db.collection.insertMany() 七个点子
db.collection.insertMany([
   {x:”a”,y:”b”,z:”c”},
   {x:”1”,y:”2”,z:”3”},
   {……………………….},
          …
          …
          …
])
其一措施作用很高。使用命令行的时候,可以先安装一个变量A=[{…},{…},{…},{…}]
在使用db.collection.insertMany(A)
2.删除
db.collection.remove({x:”a”})
趣味是剔除collection集合中x=”a”的所有数据
   3.修改
       db.collection.update({
           {x:”a”},
           {$set{y:”1”}},
           {multi:true}     //true:匹配多行 false:匹配一行 暗许为false
})
相当于  update collection set y=”1” where x=”a”
4.查询     mongodb语句        对应sql语句
   db.collection.find()        select * from collection
   db.collection.find({x:”a”})   select * from collection where
x=”a”;
   db.collection.find({x:”a”,z:{$lt:”3”}})   select * from collection
where x=”a” and z<3
   db.collection.find({x:”a”,$or{z:{$lt:”3”}}})  select * from
collection where x=”a” or z<3
   db.collection.find({x:”a”},{x:1,y:0,z:1})  select x,z from collection
where x=”a”
 
   游标
   var myCursor=db.collection.find();
   while(myCursor.hasNext()){
      print(myCursor.next())
澳门美高梅手机网站,}
更加多高档应用请查阅 db.collection.bulkWrite()
Mongodb命令与sql的自查自纠请移步至
https://docs.mongodb.com/manual/reference/sql-comparison/  查看
5.数量处理
1.Aggregation
 Aggregations operations process data records and return computed
results
Aggregation处理数量记录并重回处理结果,类比于关周全据库中的函数,存贮进度之类。限制是再次来到的多少要<16M   
假设collecion中包含x,y,z
db.collection.aggregate([
{$match:{x:”a”}},
{$group:{_id:$y,total:{$sum:z}}} 
])
证实:$group一定要有_id,这个_id能够是collection里边的某部列名,等价于
select y as _id,sum(z) as total from aggregate where x=”a” group by y
$match,$group,$limit,$sort,等措施请参见https://docs.mongodb.com/manual/meta/aggregation-quick-reference/
Aggregation与sql的照应关系请参考
https://docs.mongodb.com/manual/reference/sql-aggregation-comparison/

在《街霸》连串中的豪鬼加盟《铁拳7》之后,玩家们期待更加多其余娱乐角色可以投入到娱乐中,官方也在互联网上提倡了投票,让玩家们票选下一位在《铁拳7》中客串的角色。如今排在名次榜第四位的是《如龙》系列主演桐生一马,而原田胜弘同样对此做出了应对,他表示公司会不遗余力满足玩家须要,不过引入桐生一马必须与世嘉开展商榷,所以玩家们先不用抱太大希望。

sh.shardCollection(“<database>.<collection>”, { <key>
: <direction> } )

育碧生产的刀剑格斗游戏《荣耀战魂》第二季下载内容确认将于十月16日推出。这一赛季内容名为“阴影与力量”,两名新铁汉和和两张新地图插手到了娱乐中,当然越多的自定义道具和游戏性上的小革新自不必说。

For queries that include the shard key or the prefix of a compound shard
key, mongos can target the query at a specific shard or set of shards
对于前缀带shard
key的复合查询可以便捷稳定到某个分片,无需扫描整个数据。
此间点出了一特性质优化中央:分片集群的增删改查尽量利用shard key
For queries that do not include the shard key or the prefix of a
compound shard key, mongos performs a broadcast operation, querying all
shards in the sharded cluster
对于不包蕴shard
key的查询,就须求扫描所有分片,然后再聚合起来,影响速度。

杉果春季让利明日晌午12点快要起来了!各位准备好剁手了吧?今日的限时折扣游戏中,年底发售的《生化风险7》以史低价格148元出售,《辐射4》也再一次达到了49元的公道,而季票售价为74元。另外《崛起:布拉格之子》出售价格13元达到史低,《都市:天际线
豪华版
》19元的价位也值得购买。

Hash索引   限制:无法利用复合索引
db.collection.createIndex( { _id: “hashed” } )
db.collection.createIndex( { _id: “hashed” ,name:”hashed”} ) 
注意,那是一无所能的

“西北之龙”所指是日本周朝历史上的有名的人伊达政宗,让大家联合期待那位独眼大名会与主角威尔iam碰撞出哪些的灯火呢~

Sharding系统包涵以下多少个进度
Shard: Each shard contains a subset of the sharded data
      每一种分片包含全体数据的一小部分
Mongos: The mongos acts as a query router
      起到路由的功力
Config Server: Config servers store metadata and configuration settings
for the cluster
      存贮分片集群的配置音信

娱乐追加了两名新英豪“忍者”和“百夫长”,季票玩家可以在七月16日免费拿到那两名角色的使用权,而其余玩家需求在3月23日消费游戏内货币“铁钱”解锁。忍者是勇士阵营的刀客大侠而百夫长从属于骑士阵营,纵然官方给出了一段英豪介绍,然而从中完全不可以得知他们到底拥有啥样技能,更加多新闻还要等出售后才能领会。

唯一索引
db.members.createIndex( { “user_id”: 1 }, { unique: true } )

除却数字版游戏外,杉果周边商城今天下午还将上架PSV奥迪Q5,有意购入体验的玩家可要抓住本次抢购机会啊~

     成立Hash分片集群
1.Create the Config Server Replica Set
1)Start each member of the config server replica set.
           mongod –configsvr –replSet <setname> –dbpath
<path>
        2)Connect to one of the config servers
           mongo –host <hostname> –port <port>
        3)initiates the replica set
           rs.initiate(
              {
                 _id: “<replSetName>”,
                 configsvr: true,           注意早晚要有其一    
                 members: [
                   { _id : 0, host : “cfg1.example.net:27017” },
                   { _id : 1, host : “cfg2.example.net:27017” },
                   { _id : 2, host : “cfg3.example.net:27017” }
                 ]
               }
)
2.Create the Shard Replica Sets
1)Start each member of the shard replica set.
mongod –shardsvr –replSet <replSetname>
2)Connect to a member of the shard replica set
mongo –host <hostname> –port <port>
3)Initiate the replica set.
            rs.initiate(
              {
                 _id: “<replSetName>”,
                 configsvr: true,
                 members: [
                   { _id : 0, host : “cfg1.example.net:27017” },
                   { _id : 1, host : “cfg2.example.net:27017” },
                   { _id : 2, host : “cfg3.example.net:27017” }
                 ]
               }
)
3.Connect a mongos to the Sharded Cluster
1)Connect a mongos to the cluster
mongos –configdb <configReplSetName>/host1:port,host2:port,……
2)Connect to the mongos
mongo –host <hostname> –port <port> 
4.Add Shards to the Cluster
sh.addShard( “<replSetName>/host:port “)
5.Enable Sharding for a Database
sh.enableSharding(“<database>”)
6.Shard a Collection using Hashed Sharding
If the collection already contains data, you must create a Hashed
Indexes on the shard key using the db.collection.createIndex() method
before using shardCollection().

You can configure a secondary member for a specific purpose
鉴于种种目的,你可以随心所欲设置子节点。 
Prevent it from becoming a primary in an election, which allows it to
reside in a secondary data center or to serve as a cold standby. See
Priority 0 Replica Set Members.
使子节点成为一个冷备份,可以安装priority:0,这样,子节点就不可以出席选举了
Prevent applications from reading from it, which allows it to run
applications that require separation from normal traffic. See Hidden
Replica Set Members.
使子节点成为隐蔽节点,可以在集群故障的时候神速替换
Keep a running “historical” snapshot for use in recovery from certain
errors, such as unintentionally deleted databases. See Delayed Replica
Set Members.
使子节点成为延期备份,可以在集群人为误操作后高速还原到前半小时或一时辰的情景,延迟时间可以配备,暗中同意是一钟头。

可用参数
rs.add({_id: 1, host: “mongodb3.example.net:27017”, priority: 0,
hidden: true})
rs.add({_id: 1, host: “mongodb3.example.net:27017”, priority: 0,
hidden: true, slaveDelay:3600})
{
  _id: <string>,
  version: <int>,
  protocolVersion: <number>,
  members: [
    {
      _id: <int>,
      host: <string>,
      arbiterOnly: <boolean>,
      buildIndexes: <boolean>,
      hidden: <boolean>,
      priority: <number>,
      tags: <document>,
      slaveDelay: <int>,
      votes: <number>
    },
    …
  ],
  settings: {
    chainingAllowed : <boolean>,
    heartbeatIntervalMillis : <int>,
    heartbeatTimeoutSecs: <int>,
    electionTimeoutMillis : <int>,
    getLastErrorModes : <document>,
    getLastErrorDefaults : <document>
  }
}

      mongotop tracks and reports the current read and write activity of
a MongoDB instance, and reports these statistics on a per collection
basis.
      mongotop 对目前的mongodb实例举办跟踪和报告

分片好处:分布式读写,大规模存贮,高可用性

In-Memory引擎
the in-memory storage engine does not maintain any on-disk data,
including configuration data, indexes, user credentials, etc.
   
所有数据都放内存中,风险很高,适合于越发需要品质,且对宕机后可快速还原的数码,如省市区新闻,那种不平时写入的数额。
    mongod –storageEngine inMemory –dbpath <path> 
启用In-Memory引擎
    Warming: The in-memory storage engine does not persist data after
process shutdown.
recovery of in-memory data is impossible
   
官网有个大大的提示:内存引擎是不持久化数据的,就是一旦宕机了,就什么也没了。
Memory Use      45% RAM 或然最小1GB
   
GridFS  适用于过量16M的文件,假若低于,官网指出利用document
When to use  几时用
If your filesystem limits the number of files in a directory
当文件系统限制文件数量的时候
When you want to access information from portions of large files without
having to load whole files into memory
当唯有使用部分文件的始末时
When you want to keep your files and metadata automatically synced and
deployed across a number of systems and facilities
仰望确保文件同步的时候

For write-heavy applications, deploy sharding and add one or more shards
to a sharded cluster to distribute load among mongod instances.
本着读质量优化是增多replication(备份)来分担读压力
针对写质量优化是增多sharding(分片)来减轻写压力

      Mongodb web 控制台 http://localhost:port  port=mongod的port+1000
默认是28017

      db.serverStatus() from the shell, returns a general overview of
the status of the database
      db.serverStatus()可以查看所有mongodb的动静

连锁分片命令参考https://docs.mongodb.com/manual/reference/sharding/
13.品质测试
测试先前时代准备已经完成,由于网络的原因,近年来电话不可用,等互联网通了,就足以更进一步完善了。

If your deployment requires more than 50 members, you’ll need to use
master-slave replication. However, master-slave replication lacks the
automatic failover capabilities.
留意:如若数额过多,须要的集群规模很大,超越50个节点,那么,repleca
set如今以来,不符合,你必要转换成master-slave格局(最简便的集群,紧缺故障自动还原能力)

//对某个数据库使用慢操作日志
db.setProfilingLevel(0,100),设置那么些以往就可以查阅相应的慢操作了
0:关闭 默认
1:打开 仅记录慢操作 
2:打开 记录所有操作
慢操作定义为100微秒
查阅慢操作  db.system.profile.find( { millis : { $gt : 100 } } )
查看profile的定义 db.getProfilingStatus()
//对所有数据库使用慢操作日志
mongod –profile 1 –slowms 15
5.配置文件
设置查询时间 db.collection.find().maxTimeMS(30)
设置命令时间 db.runCommand(
                {   distinct:”collection”,
                    key:”a”,
                    maxTimeMS:40
                 }
}
        获取当前操作 db.currentOp()
        截止当前操作 db.killOp(<opid>)
6.备份
最简易的备份是使用MongoDB Cloud Manager 恐怕 Ops Manager

mongod –replSet “rs0”
rs.initiate()   //初始化
rs.conf()     //查看配置
rs.add(“mongodb1.example.net”)   //添加节点
rs.status()   //查看状态
如上所有都必须在主节点上展开

WiredTiger引擎
Document Level Concurrency  
文档级其余并行性,mmapv1是汇合级其他并行性
Snapshots and Checkpoints     快照和检查点能在mongodb
cash的时候飞快回复
Journal(write-ahead transaction log) 日志,有助于迅速还原
Compression                 帮助对聚集和文档的滑坡
Memory Use                 44% RAM可能最小1GB  使用率更高,高成效多核CUP

                              Range sharp key

移除已有节点
rs.remove(“mongod3.example.net:27017”)
对应节点关闭mongod进程 db.shutdownServer()

      db.stats() from the shell, returns a document that addresses
storage use and data volumes.
      db.stats() 重临当前数据库的情形

Sudo apt-get install –y mongodb-org
设置mongodb-org 会看重于
mongodb-org-server  包罗mongod进度,配置文件还有起头化脚本
mongodb-org-mongos 包含mongos进程
mongodb-org-shell    包含mongo命令
mongodb-org-tools    包含mongoinport
,mongodump,mongorestore,mongofiles等命令
逐一命令有怎么着用,请看下章。

10.安全
创办用户
use reporting
db.createUser(
  {
    user: “reportsUser”,
    pwd: “12345678”,
    roles: [
       { role: “read”, db: “reporting” },   //可以对reporting读
       { role: “read”, db: “products” },    //可以对products读
       { role: “read”, db: “sales” },       //可以对sales读
       { role: “readWrite”, db: “accounts” }  //可以对accounts读写
    ]
  }
)
成立角色
use admin
db.createRole(
   {
     role: “mongostatRole”,    //角色名
     privileges: [             //权限
       { resource: { cluster: true }, actions: [ “serverStatus” ] }
     ],
     roles: []    //继承哪些角色
   }
)
分配剧中人物
use reporting
db.grantRolesToUser(
    “reportsUser”,
    [
      { role: “read”, db: “accounts” }
    ]
)

db.collection.totalIndexSize()  查看索引的轻重,物理内存最好大于它

Priority 0 Replica Set Members      设置priority的目的
  A priority 0 member is a secondary that cannot become primary
  A priority 0 member can function as a standby
     in sets with varied hardware or geographic distribution, a priority
0 standby ensures that only qualified members become primary
   Hidden Replica Set Members       设置隐藏节点的目标
     A hidden member maintains a copy of the primary’s data set but is
invisible to client applications
     Use hidden members for dedicated tasks such as reporting and
backups
   Delayed Replica Set Members       设置延迟节点的目标
     a delayed member’s data set reflects an earlier, or delayed, state
of the set
     Must be priority 0 members. Set the priority to 0 to prevent a
delayed member from becoming primary.
Should be hidden members. Always prevent applications from seeing and
querying delayed members
  
   Oplog      日志
     The oplog (operations log) is a special capped collection that
keeps a rolling record of all operations that modify the data stored in
your databases.
     记录所有的操作,可以因此它来过来数据。
     The default oplog size depends on the storage engine:
Engine   Default Size    Lower Bound       Upper Bound
In-Memory Storage Engine 5% of physical memory 50 MB 50 GB
WiredTiger Storage Engine 5% of free disk space 990 MB 50 GB
MMAPv1 Storage Engine 5% of free disk space 990 MB 50 GB
默许大小
引擎        大小         下限        上限
In-Memory   5%内存       50M        50G
      wiredTiger   5%剩余磁盘   990M       50G
      MMAPv1    5%剩余磁盘   990M       50G

修改节点优先级
cfg = rs.conf()
cfg.members[2].priority = 0.5   //修改节点的优先级
rs.reconfig(cfg)

12.分片
Sharding is a method for distributing data across multiple machines.
MongoDB uses sharding to support deployments with very large data sets
and high throughput operations.
Sharding就是将大规模数据分片,各种分片各自占用一个mongod进度,方便处理。ar

db.getRole( “read”, { showPrivileges: true } ) 查看剧中人物权限
Mongodb内建角色
Read    provides the ability to read data on all non-system
collections
读      提供除了系统表之外任何表的读取功效
readWrite  provides all the privileges of the read role and the ability
to modify data on all non-system collections
   读写    提供除系统表之外任何表的读写功用
   详细资料请参考
https://docs.mongodb.com/manual/core/security-built-in-roles/
亟需专注的某些:
a role can only include privileges that apply to its database and can
only inherit from other roles in its database,except for database
admin.
趣味是,创设的剧中人物只对脚下数据库有效,除了在admin数据库中成立的剧中人物。Admin中开创的剧中人物可以对其他数据库举办操作
Ensure that the HTTP status interface, the REST API, and the JSON API
are all disabled in production environments to prevent potential data
exposure and vulnerability to attackers.
生育条件的时候请保管关闭http,rest api,json api 功效。

TTL索引    Time To Live
限制:无法对_id使用,不扶助复合索引,eventlog无法使capped collection
db.eventlog.createIndex( { name: 1 }, { expireAfterSeconds: 3600 } )

启动mongodb
sudo mongod
开行的时候有局地参数,可以经过mongod –help查看
暗中同意端口为27017,你也可以通过mongod  –port=xxx 来改变端口。
诚如常用的是 mongod  -f /etc/mongodb.config 来运营  
mongodb.config怎么样布置请
停止mongodb
官网推荐的是 mongo 进到命令行里
use admin   //转到admin数据库
db.shutdownServer()   //停止mongodb
也足以一贯kill mongodb的历程
ps –ef|grep mongodb   找到mongodb的进程pid
Kill -9 pid

成立Range分片集群
  
步骤和创造Hash分片集群一致,除了第6步,Range分片创制的是平时索引,而Hash分片创设的是hash索引

With the WiredTiger storage engine, use of XFS is strongly recommended
to avoid performance issues that may occur when using EXT4 with
WiredTiger
应用wiredTiger引擎强烈提出使用xfs文件系统。xfs文件系统比ext4文件系统对mongodb更温馨

集群索引
1.Stop One Secondary                mongod –port 47017
2.Build the Index                    db.records.createIndex( { username:
1 } )
3.Restart the Program mongod         mongod –port 27017 –replSet rs0
率先步,甘休mongod,在另一个端口运转单例mongod。
第二步,在其上开创索引。
其三步,截至单例mongod,使用原来的集群配置再一次运维。

使用bing_ip限制访问的ip
至于连锁权限处理的措施请参考
https://docs.mongodb.com/manual/reference/security/
11.集群
A replica set in MongoDB is a group of mongod processes that maintain
the same data set
The primary node receives all write operations。
replica set
可以聚集四个mongod进程为同一份数据服务,且只有主节点才能写。
The secondaries replicate the primary’s oplog and apply the operations
to their data sets such that the secondaries’ data sets reflect the
primary’s data set
子节点看重于主节点的日记举行数量同步。
Replica set members send heartbeats (pings) to each other every two
seconds. If a heartbeat does not return within 10 seconds, the other
members mark the delinquent member as inaccessible
集群中种种节点互相发送ping音信,每2分钟四回。固然某个节点10秒内不可以回答,则集群就会标识这几个节点不能连接。
The purpose of an arbiter is to maintain a quorum in a replica set by
responding to heartbeat and election requests by other replica set
members
arbiter 的功能是检测集群的健康境况,并开展选举。
If your replica set has an even number of members, add an arbiter to
obtain a majority of votes in an election for primary
指出是,当集群数量很多的时候,单独一台机子安装arbiter,专门负责集群的公推。
When a primary does not communicate with the other members of the set
for more than 10 seconds, an eligible secondary will hold an election to
elect itself the new primary
当子节点链接主节点时间超越10秒,子节点会认为,主节点crash了,然后子节点对集群发出选举,提名本身变成新的主节点。
Primary : receives all write operations.   
Seconderies: replicate operations from the primary to maintain an
identical data set
具有写均要透过主节点,所有子节点均是主节点的一个备份。
A replica set can have up to 50 members but only 7 voting members
Replica set 最近只允许最多50个节点,允许最多有7个投票节点。

8.索引
格式 db.collection.createIndex( {<key and index type
specification>, <options>},{xxx1:xxx2} )
key:要索引的列名 options: 1|-1  顺序依然逆序索引
xxx1:索引参数名   xxx2:索引参数值
对大气数额索引会影响属性,所以一般会举行后台索引
db.collection.createIndex({key:options},{backgroup:true})
对索引举行命名
db.collection.createIndex({key:options},{name:yourName })

发表评论

电子邮件地址不会被公开。 必填项已用*标注