一、什么是MongoDB ?

MongoDB一种由C++语言编写的,是一个基于分布式文件存储的非关系型数据库(NoSql),是一种强大、灵活、可扩展的数据存储方式,因为MongoDB是文档模型,数据结构由键值(key=>value)对组成,

似于 JSON 对象,字段值可以包含其他文档,数组及文档数组。自由灵活很高。

同时对于大数据量、高并发、弱事务的互联网应用,与高负载的情况下,添加更多的节点,可以保证服务器性能。

MongoDB内置的水平扩展机制提供了从百万到十亿级别的数据量处理能力,还对MapReduce式聚合的支持,以及对地理空间索引的支持。

MongoDB 旨在为WEB应用提供可扩展的高性能数据存储解决方案。

二、MongoDB 优缺点

优点

  • 文档结构的存储方式,能够更便捷的获取数据
  • 内置GridFS,支持大容量的存储
  • 海量数据下,性能优越
  • 动态查询
  • 全索引支持,扩展到内部对象和内嵌数组
  • 查询记录分析
  • 快速,就地更新
  • 高效存储二进制大对象 (比如照片和视频)
  • 复制(复制集)和支持自动故障恢复
  • 内置 Auto- Sharding 自动分片支持云级扩展性,分片简单
  • MapReduce 支持复杂聚合

缺点

  • 不支持事务操作
  • MongoDB 占用空间过大 (不过这个确定对于目前快速下跌的硬盘价格来说,也不算什么缺点了)
  • MongoDB没有如MySQL那样成熟的维护工具
  • 无法进行关联表查询,不适用于关系多的数据
  • 复杂聚合操作通过mapreduce创建,速度慢
  • 模式自由,自由灵活的文件存储格式带来的数据错
  • MongoDB 在你删除记录后不会在文件系统回收空间。除非你删掉数据库。但是空间没有被浪费

三、优缺点详细解释

与关系型数据库相比,MongoDB的优点:

1.内置GridFS,支持大容量的存储:

  GridFS是一个出色的分布式文件系统,可以支持海量的数据存储。 内置了GridFS了MongoDB,能够满足对大数据集的快速范围查询。

2.内置 Auto- Sharding 自动分片支持云级扩展性,分片简单

  提供基于Range的Auto Sharding机制:

  一个collection可按照记录的范围,分成若干个段,切分到不同的Shard上。

  Shards可以和复制结合,配合Replica sets能够实现Sharding+fail-over,不同的Shard之间可以负载均衡。
  查询是对客户端是透明的。客户端执行查询,统计,MapReduce等操作,这些会被MongoDB自动路由到后端的数据节点。
  这让我们关注于自己的业务,适当的 时候可以无痛的升级。MongoDB的Sharding设计能力最大可支持约20 petabytes,足以支撑一般应用。
  这可以保证MongoDB运行在便宜的PC服务器集群上。PC集群扩充起来非常方便并且成本很低,避免了“sharding”操作的复杂性和成本。

3.海量数据下,性能优越:

  在使用场合下,千万级别的文档对象,近10G的数据,对有索引的ID的查询不会比mysql慢,mysql实际无法胜任大数据量下任意字段的查询,所以mongo对非索引字段的查询,则是更胜一筹,

  而mongodb的查询性与写入性能同样很令人满意,同样写入百万级别的数据,基本10分钟以下可以解决且mongodb都远算不上是CPU杀手。

4.全索引支持,扩展到内部对象和内嵌数组

  索引通常能够极大的提高查询的效率,如果没有索引,MongoDB在读取数据时必须扫描集合中的每个文件并选取那些符合查询条件的记录。

  这种扫描全集合的查询效率是非常低的,特别在处理大量的数据时,查询可以要花费几十秒甚至几分钟,这对网站的性能是非常致命的。

  索引是特殊的数据结构,索引存储在一个易于遍历读取的数据集合中,索引是对数据库表中一列或多列的值进行排序的一种结构。

5.MapReduce 支持复杂聚合

  MongoDB中聚合(aggregate)主要用于处理数据(诸如统计平均值,求和等),并返回计算后的数据结果。有点类似sql语句中的 count(*)。

与关系型数据库相比,MongoDB的缺点:

mongodb不支持事务操作:

  所以事务要求严格的系统(如果银行系统)肯定不能用它。

mongodb不支持事务操作:

  所以事务要求严格的系统(如果银行系统)肯定不能用它。

mongodb占用空间过大:

关于其原因,在官方的FAQ中,提到有如下几个方面:

1、空间的预分配:为避免形成过多的硬盘碎片,mongodb每次空间不足时都会申请生成一大块的硬盘空间,而且申请的量从64M、128M、256M那 样的指数递增,直到2G为单个文件的最大体积。随着数据量的增加,你可以在其数据目录里看到这些整块生成容量不断递增的文件。

2、字段名所占用的空间:为了保持每个记录内的结构信息用于查询,mongodb需要把每个字段的key-value都以BSON的形式存储,如果 value域相对于key域并不大,比如存放数值型的数据,则数据的overhead是最大的。一种减少空间占用的方法是把字段名尽量取短一些,这样占用 空间就小了,但这就要求在易读性与空间占用上作为权衡了。

3、删除记录不释放空间:这很容易理解,为避免记录删除后的数据的大规模挪动,原记录空间不删除,只标记“已删除”即可,以后还可以重复利用。

4、可以定期运行db.repairDatabase()来整理记录,但这个过程会比较缓慢

MongoDB没有如MySQL那样成熟的维护工具,这对于开发和IT运营都是个值得注意的地方。

4.安装前言

monogb还没有win10版本

https://docs.mongodb.com/v3.0/tutorial/install-mongodb-on-windows/

5.安装mongo

1.安装和配置

第一步:解压到一个盘上,例如我的解压的目录D:\Zoo\mongodb,如图所示:

第二步:配置存放日志和数据的目录,不然mongoDB无法启动,如图所示:

通过帮助命令,找到了(1)--logpath arg: arg是设置存放日志的路径(2)--dbpath arg:arg是存放数据文件的路径

  1. C:\Users\WQBin>mongod --help
  2. Options:
  3. --networkMessageCompressors arg (=snappy,zstd,zlib)
  4. Comma-separated list of compressors to
  5. use for network messages
  6.  
  7. General options:
  8. -h [ --help ] Show this usage information
  9. --version Show version information
  10. -f [ --config ] arg Configuration file specifying
  11. additional options
  12. --configExpand arg Process expansion directives in config
  13. file (none, exec, rest)
  14. --ipv6 Enable IPv6 support (disabled by
  15. default)
  16. --listenBacklog arg (=) Set socket listen backlog size
  17. --maxConns arg (=) Max number of simultaneous connections
  18. --pidfilepath arg Full path to pidfile (if not set, no
  19. pidfile is created)
  20. --timeZoneInfo arg Full path to time zone info directory,
  21. e.g. /usr/share/zoneinfo
  22. -v [ --verbose ] [=arg(=v)] Be more verbose (include multiple times
  23. for more verbosity e.g. -vvvvv)
  24. --quiet Quieter output
  25. --port arg Specify port number - by default
  26. --logpath arg Log file to send write to instead of
  27. stdout - has to be a file, not
  28. directory
  29. --logappend Append to logpath instead of
  30. over-writing
  31. --logRotate arg Set the log rotation behavior
  32. (rename|reopen)
  33. --timeStampFormat arg Desired format for timestamps in log
  34. messages. One of ctime, iso8601-utc or
  35. iso8601-local
  36. --setParameter arg Set a configurable parameter
  37. --bind_ip arg Comma separated list of ip addresses to
  38. listen on - localhost by default
  39. --bind_ip_all Bind to all ip addresses
  40. --noauth Run without security
  41. --transitionToAuth For rolling access control upgrade.
  42. Attempt to authenticate over outgoing
  43. connections and proceed regardless of
  44. success. Accept incoming connections
  45. with or without authentication.
  46. --slowms arg (=) Value of slow for profile and console
  47. log
  48. --slowOpSampleRate arg (=) Fraction of slow ops to include in the
  49. profile and console log
  50. --auth Run with security
  51. --clusterIpSourceWhitelist arg Network CIDR specification of permitted
  52. origin for `__system` access
  53. --profile arg =off =slow, =all
  54. --cpu Periodically show cpu and iowait
  55. utilization
  56. --sysinfo Print some diagnostic system
  57. information
  58. --noscripting Disable scripting engine
  59. --notablescan Do not allow table scans
  60. --keyFile arg Private key for cluster authentication
  61. --clusterAuthMode arg Authentication mode used for cluster
  62. authentication. Alternatives are
  63. (keyFile|sendKeyFile|sendX509|x509)
  64.  
  65. Replication options:
  66. --oplogSize arg Size to use (in MB) for replication op
  67. log. default is % of disk space (i.e.
  68. large is good)
  69.  
  70. Replica set options:
  71. --replSet arg arg is <setname>[/<optionalseedhostlist
  72. >]
  73. --enableMajorityReadConcern [=arg(=)] (=)
  74. Enables majority readConcern
  75.  
  76. Sharding options:
  77. --configsvr Declare this is a config db of a
  78. cluster; default port ; default
  79. dir /data/configdb
  80. --shardsvr Declare this is a shard db of a
  81. cluster; default port
  82.  
  83. Storage options:
  84. --storageEngine arg What storage engine to use - defaults
  85. to wiredTiger if no data files present
  86. --dbpath arg Directory for datafiles - defaults to
  87. \data\db\ which is C:\data\db\ based on
  88. the current working drive
  89. --directoryperdb Each database will be stored in a
  90. separate directory
  91. --syncdelay arg (=) Seconds between disk syncs (=never,
  92. but not recommended)
  93. --journalCommitInterval arg (=) how often to group/batch commit (ms)
  94. --noIndexBuildRetry Do not retry any index builds that were
  95. interrupted by shutdown
  96. --upgrade Upgrade db if needed
  97. --repair Run repair on all dbs
  98. --journal Enable journaling
  99. --nojournal Disable journaling (journaling is on by
  100. default for bit)
  101.  
  102. TLS Options:
  103. --tlsOnNormalPorts Use TLS on configured ports
  104. --tlsMode arg Set the TLS operation mode
  105. (disabled|allowTLS|preferTLS|requireTLS
  106. )
  107. --tlsCertificateKeyFile arg Certificate and key file for TLS
  108. --tlsCertificateKeyFilePassword arg Password to unlock key in the TLS
  109. certificate key file
  110. --tlsClusterFile arg Key file for internal TLS
  111. authentication
  112. --tlsClusterPassword arg Internal authentication key file
  113. password
  114. --tlsCAFile arg Certificate Authority file for TLS
  115. --tlsClusterCAFile arg CA used for verifying remotes during
  116. inbound connections
  117. --tlsCRLFile arg Certificate Revocation List file for
  118. TLS
  119. --tlsDisabledProtocols arg Comma separated list of TLS protocols
  120. to disable [TLS1_0,TLS1_1,TLS1_2]
  121. --tlsAllowConnectionsWithoutCertificates
  122. Allow client to connect without
  123. presenting a certificate
  124. --tlsAllowInvalidHostnames Allow server certificates to provide
  125. non-matching hostnames
  126. --tlsAllowInvalidCertificates Allow connections to servers with
  127. invalid certificates
  128. --tlsFIPSMode Activate FIPS - mode at startup
  129. --tlsCertificateSelector arg TLS Certificate in system store
  130. --tlsClusterCertificateSelector arg SSL/TLS Certificate in system store for
  131. internal TLS authentication
  132. --tlsLogVersions arg Comma separated list of TLS protocols
  133. to log on connect [TLS1_0,TLS1_1,TLS1_2
  134. ]
  135.  
  136. Windows Service Control Manager options:
  137. --install Install Windows service
  138. --remove Remove Windows service
  139. --reinstall Reinstall Windows service (equivalent
  140. to --remove followed by --install)
  141. --serviceName arg Windows service name
  142. --serviceDisplayName arg Windows service display name
  143. --serviceDescription arg Windows service description
  144. --serviceUser arg Account for service execution
  145. --servicePassword arg Password used to authenticate
  146. serviceUser
  147.  
  148. Free Monitoring Options:
  149. --enableFreeMonitoring arg Enable Cloud Free Monitoring
  150. (on|runtime|off)
  151. --freeMonitoringTag arg Cloud Free Monitoring Tags
  152.  
  153. WiredTiger options:
  154. --wiredTigerCacheSizeGB arg Maximum amount of memory to allocate
  155. for cache; Defaults to / of physical
  156. RAM
  157. --wiredTigerJournalCompressor arg (=snappy)
  158. Use a compressor for log records
  159. [none|snappy|zlib|zstd]
  160. --wiredTigerDirectoryForIndexes Put indexes and data in different
  161. directories
  162. --wiredTigerMaxCacheOverflowFileSizeGB arg (=)
  163. Maximum amount of disk space to use for
  164. cache overflow; Defaults to
  165. (unbounded)
  166. --wiredTigerCollectionBlockCompressor arg (=snappy)
  167. Block compression algorithm for
  168. collection data [none|snappy|zlib|zstd]
  169. --wiredTigerIndexPrefixCompression arg (=)
  170. Use prefix compression on row-store
  171. leaf pages

mongod --help

先在目录下建立相关的存储日志的文件和存储数据的文件夹

  1. mongod --logpath D:\Zoo\mongodb\logs\log
  2. mongod --dbpath D:\Zoo\mongodb\data

这样就建立一个monog的服务端:

也可以直接把配置写入文件中,直接mongod  --config d:\Zoo\mongodb\mongodb.config打开相应的服务端

通过mongo命令直接打开客户端:

6.添加MongoDB到Windows Service

第一步:安装MongoDB自动服务

我们当我们把运行MongoDB服务器的dos命令界面关掉,MongoDB的客户端也随之停止。

如果把mongo 的服务端添加到Windows Service,然后在命令行上启动服务和关闭服务,这样方便我们操作和管理服务,用到的命令是--install设定安装MongoDB为服务器到Windows Service。

第二步:启动/关闭MongoDB服务

netstart mongodb 启动MongoDB服务

net stop mongodb 启动MongoDB服

mongodb的安装与使用(一)的更多相关文章

  1. MongoDB下载安装与简单增删改查

    Windows下MongoDB的安装和配置.启动和停止 下载地址:MongoDB的官方下载网址是:https://www.mongodb.org/downloads 安装步骤1. 点击下载的mongo ...

  2. MongoDB的安装与设置MongoDB服务

    Mongo DB 是目前在IT行业非常流行的一种非关系型数据库(NoSql),其灵活的数据存储方式备受当前IT从业人员的青睐.Mongo DB很好的实现了面向对象的思想(OO思想),在Mongo DB ...

  3. Linux下MongoDB服务安装

    Linux下MongoDB服务安装 MongoDB是一个基于分布式文件存储的数据库.由C++语言编写.旨在为WEB应用提供可扩展的高性能数据存储解决方案.MongoDB是一个介于关系数据库和非关系数据 ...

  4. MongoDB学习-安装流程

    MongoDB是一个介于关系数据库和非关系数据库之间的产品,是非关系数据库当中功能最丰富,最像关系数据库的. 支持的数据结构非常松散,是类似json的bjson格式,因此可以存储比较复杂的数据类型. ...

  5. mongodb(二) 安装和使用

    mongodb的安装和使用 最近的项目需要使用到mongodb,从而开始熟悉nosql,有了本篇文章,记录和方便他人. mongodb的安装 下载地址:http://www.mongodb.org/d ...

  6. MongoDB的安装及配置

    MongoDB 是目前在IT行业非常流行的一种非关系型数据库(NoSql),其灵活的数据存储方式备受当前IT从业人员的青睐. Windows (1). 登录Mongodb官网点击下载 (2). 将zi ...

  7. MongoDB的安装 转

    第1章 MongoDB的安装 (黎明你好原创作品,转载请注明) 1.1 MongoDB简介 MongoDB是一个基于分布式文件存储的数据库开源项目.由C++语言编写,旨在为WEB应用提供可护展的高性能 ...

  8. MongoDB的安装,配置与开机自启动

    关于简介不多说百度去吧少年.. MongoDB详细安装: 1.进入官网,点击DOWNLOAD MONGODB,下载所需要的版本.. 我这里把下载的文件放在d\MongoDB文件夹下,点击下载的官方镜像 ...

  9. MongoDB(二)——安装配置了解

    前边介绍了MongoDB的大概理论知识,这篇来对MongoDB进行一下安装使用,支持安装在windows和linux上,当然了很多其它情况下我们是安装在linux上,由于毕竟server用linux的 ...

  10. MongoDB本地安装与启用(windows )

    MongoDB的安装与MongoDB服务配置 Mongo DB 是目前在IT行业非常流行的一种非关系型数据库(NoSql),其灵活的数据存储方式备受当前IT从业人员的青睐.Mongo DB很好的实现了 ...

随机推荐

  1. NameNode 和 SecondaryNameNode

    1. NN 和 2NN 工作机制 NameNode 会产生在磁盘中备份元数据的FsImage; 每当元数据有更新或者添加数据时,修改内存中的元数据并追加到Edits中; SecondaryNameNo ...

  2. 《Brennan's Guide to Inline Assembly》学习笔记

    原文见Brennan's Guide to Inline Assembly. AT&T语法 vs Intel语法 DJGPP是基于GCC的,因此它使用AT&T/UNIT语法,这和Int ...

  3. brew update慢,brew install慢如何解决?

    主要是资源访问太慢造成的,替换默认源镜像就行. brew使用国内镜像源 这里用中科大的,另外还有清华的可用     1 2 3 4 5 6 7 8 9 10 # 步骤一 cd "$(brew ...

  4. Junit测试类中如何调用Http通信

    在使用Junit做测试的时候,有时候需要调用Http通信,无论是request还是response或者是session会话,那么在测试类里该如何调用呢,其实很简单,spring给我们提供了三个类 or ...

  5. Web安全小结之前端

  6. 第9周cf刷题(dp)

    Problems(1300-1600) an ac a day keeps the doctor away Gas Pipeline (1500) 2019.10.28 题意: 管道工人需要在一段凹凸 ...

  7. PHP获取今日、昨日、本周、上周、本月、上月、本季、上季、今年、去年

    //今天开始$beginToday = date('Y-m-d 00:00:00', time());//今天结束$endToday = date('Y-m-d 23:59:59', time()); ...

  8. linux下mysql启动 Starting MySQL. ERROR! The server quit without updating PID file(xxx/x.pid)

    service mysql start 报错: Starting MySQL. ERROR! The server quit without updating PID file(xxx/x.pid) ...

  9. react的状态管理

    近两年前端技术的发展如火如荼,大量的前端项目都在使用或转向 Vue 和 React 的阵营, 由前端渲染页面的单页应用占比也越来越高,这就代表前端工作的复杂度也在直线上升,前端页面上展示的信息越来越多 ...

  10. python 识别图像主题并切割

    两种办法,一种是用百度的API,效果还可以,不过好像每天有50次的调用的限制 from aip import AipImageClassify import cv2 """ ...