早报:《巫师3》开发者告诉你于娱乐被可知学到什么

开世界第一人称射击游戏《狙击手:幽灵战士3》已经于昨日正规发售,这款游戏获得的评不强,18下媒体于来的Metacritic评分仅来54私分,而来自媒体的评论道按照作类似于一致统低本钱的B级片,你可从中体会及爆头、枪战、潜入暗杀、开放世界等等确实能带来简单粗暴乐趣之情,但是本着这些内容的卷入还远远不够。如果您针对狙击有着不同寻常的趣味,不妨尝试一下这款作品。

使用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独投票节点。

出外媒采访了《巫师3》开发商的职工们,想打听这些恐怕是当代极出色之RPG开发者们们好玩什么游戏。毫不令人始料未及之是,大多数丁尽欣赏的玩乐是《巫师3》。

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()  //获取索引

4.《漫威英雄vs卡普空:无限》发售日确定,九月开讲

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

《哥特王朝2》游戏画面

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更团结

另外,《生化危机7》将于五平活动里以杉果以史低价格销售,各位还并未下手的玩家不妨设想入手。

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引擎只有企业版才来,使用内存,速度还快,单对内存要求非常高。

对今即使想感受漫威与卡普空英雄乱斗的玩家,《终极漫威英雄vs卡普空3》在杉果有卖,95长之标价也显得亲民不丢。

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
      存贮分片集群的配备信息

于是,在座的各位玩家们,不要管玩游戏当成纯粹的排解,从内可如法炮制到不少事物啊~

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” }
    ]
)

《狙击手:幽灵战士3》目前在杉果有售,对于好玩一枪爆头后四溅的血花又想打至同样慢性官方中文游戏的玩家可以设想请。

                               Hash sharp key

另外,游戏被原定包含的几近总人口模式暂时并未推出,玩家在2017年第三季度才能够通过免费更新得这项内容。

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

2.《巫师3》开发者们还喜欢玩什么游戏?

分片策略    优点                     缺点                   适用
  Hash      数据均匀分布             顺序查询慢             基本适用
  Range     可对有阶段分片       数据易出现头重脚轻   按等级查询

1.《生化危机7》DLC“不是强悍”延期,克里斯我们晚些再见吧

集群的时如果确保时间一起(NTP)
4.性能优化
For read-heavy applications, increase the size of your replica set and
distribute read operations to secondary members.

5.官方剧透:距离杉果春季促销只残留2龙,周边商城为打折

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.stats() from the shell, returns a document that addresses
storage use and data volumes.
      db.stats() 返回时数据库的状态

当然,也出部分员工见来了另兴趣,《巫师3》的上位关卡设计师的最爱是《雷神之锤》,这款游戏简洁的镜头更发凸显了彼卡设计之精美,想必就员设计师从中学到了众多物;首席叙事设计师最爱的游乐是《哥特王朝2》,这款游戏被的NPC全都有正活的个性,恐怕《巫师3》中每个NPC都备和谐之活着就同样计划吧自这款经典游戏中取得了通过;游戏总监最易之创作是《创世纪7:黑门》,这款古老的RPG游戏是欧美RPG的鼻祖之一;游戏的首席剧本作家最易的则是《铁血联盟2》,这款打之广开放世界或为对《巫师3》的造作造成了影响吧。

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

至于“杉果游戏”:一下啊国内单机玩家操碎了心头之游玩代理发行平台。已与B社、卡普空、华纳、万代南梦宫顶70不必要贱中外厂商建立合作,致力为用生化危机、上古老卷轴、辐射、蝙蝠侠、黑暗的魂等单机游戏带被中国玩家。

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
分片集群不可知创其他列的绝无仅有索引

公恐怕就习惯了当杉果购买数字版游戏,但是呢变化忘了杉果的泛商城哦~在本次春季促销中,杉果周边商城为以打开同优惠,《生化危机》限量周边及《堕落之王》典藏雕像将坐半价出售,PS4国行实体游戏有10%off的优胜,而当前当中外都高居缺货状态的PSVR也会见在杉果出售现货!

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 })

世家好!今天卡普空公布《漫威英雄vs卡普空:无限》发售日;《狙击手:幽灵战士3》评分出炉;距离杉果春季促销只留少天。更多新闻,请圈今朝早报。

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

本来预定推出的《生化危机7》免费DLC《不是勇于》(Not A
Hero)确认延期,具体发售日未知。这款DLC以多重中之尽角色“克里斯”为主角,且会盖第三人称射击的形式进行娱乐。对于爱好《生化危机4/5/6》的发射体验的玩家来说应该会特别好听。

可用参数
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>
  }
}

《创世纪7》游戏画面

创造Range分片集群
  
步骤和创造Hash分片集群一致,除了第6步,Range分片创建的是平凡索引,而Hash分片创建的凡hash索引

娱乐时底预售价格也284头,预购奖励呢新兵托尔、杀意隆、角斗士浩克和洛克人的皮,而含有未来拿推出的角色DLC的雕栏玉砌版售价427长。

移除已发生节点
rs.remove(“mongod3.example.net:27017”)
本着承诺节点关闭mongod进程 db.shutdownServer()

3.《狙击手:幽灵战士3》评分汇总,低本钱的B级片

      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实例进行跟踪及喻

《铁血联盟2》游戏画面

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

卡普空今日通告了《漫威英雄vs卡普空:无限》的出售日9月19日,现在娱乐都拉开预售。游戏之故事预告片也顺便放出,显然这次卡普空不备推出一个《街霸5》一样的不够单机内容之一日游了,即使是不喜欢网战的玩家也能高高兴兴地体会单机内容。

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

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 显示操作(增删改查)的次数

      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() 返回集群的状态

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默认使用60%底内存,且最小1GB,推荐是单机内存10G
开行时得通过mongod –wiredTigerCacheSizeGB=xxx 来装以多少内存
wiredTigerCacheSizeGB: Defines the maximum size of the internal cache
that WiredTiger will use for all data.

     创建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().

相关分片命令参考https://docs.mongodb.com/manual/reference/sharding/
13.性能测试
测试首准备就终结,由于网络的因,目前电话不可用,等网络通了,就得更完善了。

You cannot change the shard key after sharding, nor can you unshard a
sharded collection
小心:以key=x分片之后虽未克以窜为key=y了,集群分片之后吧无力回天还原为不分片前之状态了。

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

启动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

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

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

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

  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/

稀疏索引起
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 } )

      db.serverStatus() from the shell, returns a general overview of
the status of the database
      db.serverStatus()可以翻所有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      50% 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(分片)来减轻写压力

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)

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.
使子节点成为延期备份,可以以集群人为误操作后迅速恢复到前半时要平等时之状态,延迟时间可以配备,默认是一律钟头。

mongod –replSet “rs0”
rs.initiate()   //初始化
rs.conf()     //查看配置
rs.add(“mongodb1.example.net”)   //添加节点
rs.status()   //查看状态
上述所有都不能不以主节点上进行

                              Range sharp key

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 功能。

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等命令
各个命令有啊用,请看下章。

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/

顾,官网如是说
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”)

//对某个数据库使用慢操作日志
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

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.members.createIndex( { “user_id”: 1 }, { unique: true } )

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

聚群索引
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,使用原来的集群配置更启航。

chunks stores the binary chunks.  chunks集合存贮文件的第二前行制块
files stores the file’s metadata.    files集合存贮文件的讲述信息

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的查询,就待扫描所有分片,然后还聚起来,影响速度。

复合索引  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排序

                   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各来怎么样区别,这些请上官网自行查看

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方面也做的不好。

WiredTiger引擎
Document Level Concurrency  
文档级别之并行性,mmapv1是集级别之并行性
Snapshots and Checkpoints     快照和检查点能以mongodb
cash的时刻快恢复
Journal(write-ahead transaction log) 日约,有助于迅速还原
Compression                 支持对聚集和文档的减
Memory Use                 60% RAM或者太小1GB  使用率还胜,高效用几近核CUP

发表评论

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