[Reprint] MongoDB introduction and download and installation

The first section of MongoDB introduction and download and installation

introduction

    MongoDB is a product between relational databases and non-relational databases. It is the most feature-rich and most like relational databases among non-relational databases. The data structure it supports is very loose and is a bjson format similar to json, so it can store more complex data types. The biggest feature of Mongo is that the query language it supports is very powerful. Its syntax is somewhat similar to the object-oriented query language. It can almost realize most functions similar to single-table query in relational databases, and it also supports indexing of data.

It is characterized by high performance, easy deployment, easy use, and it is very convenient to store data. The main functional features are:

  • Collection-oriented storage, easy to store object type data.
  • Pattern freedom.
  • Support dynamic query.
  • Full indexing is supported, including inner objects.
  • Support query.
  • Replication and failback are supported.
  • Use efficient binary data storage, including large objects (such as videos, etc.).
  • Fragmentation is automatically handled to support scalability at the cloud level
  • Support RUBY, PYTHON, JAVA, C++, PHP and other languages.
  • The file storage format is BSON (an extension of JSON)
  • web-accessible

The so-called "collection-oriented" (Collenction-Orented) means that data is grouped and stored in a data set, which is called a collection. Each collection has a unique identifying name in the database and can contain an unlimited number of documents. The concept of a collection is similar to a table in a relational database (RDBMS), except that it does not need to define any schema.
Schema-free means that for a file stored in a mongodb database, we do not need to know any structure definition of it. If desired, you can store files of different structures in the same database.
Documents stored in a collection are stored as key-value pairs. The key is used to uniquely identify a document and is of type string, while the value can be of various complex file types. We call this storage form BSON (Binary Serialized dOcument Format).

The MongoDB server can run on Linux, Windows or OS X platforms, supports 32-bit and 64-bit applications, and the default port is 27017. It is recommended to run on a 64-bit platform because MongoDB

The maximum file size supported when running in 32-bit mode is 2GB.

MongoDB stores data in files (the default path is: /data/db), and uses memory-mapped files for management to improve efficiency.

The above is just a random selection. In fact, it is a non-traditional non-relational database. Now it is classified into the document database category. Note that the maximum file supported by a 32-bit operating system is 2GB, so friends who want to do mass storage of large files should choose 64-bit ones. System installation. Let's start our download and installation journey.

1. Download

The official website of MongoDB is: http://www.mongodb.org/

The latest version of MongoDB is downloaded under the DownLoad menu of the official website: http://www.mongodb.org/downloads 

I chose Windows 32-bit version 1.8.1

The MongoDB For .net driver development kit is located under the Driver menu on the official website (including other language development links): https://github.com/mongodb/mongo-csharp-driver/downloads

My operating system is Windows7 Professional Edition, I choose MongoDB version as Windows 32-bit 1.8.1, and the development kit is VS2008 version

Let's start our installation process

2. Installation

1. Unzip mongodb-win32-i386-1.8.1.zip, create the path C:\Program Files\mongodb, and copy the unzipped Bin file to this folder

2. Create a Data folder C:\Program Files\mongodb\data under C:\Program Files\mongodb, and then create two folders, db and log, respectively. So far, there are the following folders under mongodb

C:\Program Files\mongodb\bin

C:\Program Files\mongodb\data\db

C:\Program Files\mongodb\data\log

在log文件夹下创建一个日志文件MongoDB.log,即C:\Program Files\mongodb\data\log\MongoDB.log

完成以上工作后,你为奇怪为什么要建立这些文件夹(因为,Mongodb安装需要这些文件夹,默认安装是不用创建,但是文件都为安装到C:\data\下)

 

3.几种安装方式介绍

3.1 程序启动方式

    运行cmd.exe 进入DOS命中界面

> cd C:\Program Files\mongodb\bin

> C:\Program Files\mongodb\bin>mongod -dbpath "C:\Program Files\mongodb\data\db"

执行此命令即将mongodb的数据库文件创建到C:\Program Files\mongodb\data\db 目录,不出意外的会看到命令最后一行sucess的成功提示

此时数据库就已启动,该界面为Mongo的启动程序,关闭后可直接双击bin下的mongod.exe  (注意是d,这个是启动程序)

启动程序开启后,再运行mongo.exe 程序(注意没有d) ,界面如下

测试数据库操作

>help  (查看相关信息)

>db.foo.insert({a:1})    (往foo表插入a,1字段值,foo表为默认表)

>db.foo.find()                (查看foo表数据)

结果如下:

  

可以看到插入了3条记录分别人a,cctv,set 。

当mongod.exe被关闭时,mongo.exe 就无法连接到数据库了,因此每次想使用mongodb数据库都要开启mongod.exe程序,所以比较麻烦,接下来我们将

MongoDB安装为windows服务吧

3.2 windows service方式

运行cmd.exe

> cd C:\Program Files\mongodb\bin

> C:\Program Files\mongodb\bin>mongod --dbpath "C:\Program Files\mongodb\data\db" --logpath "C:\Program Files\mongodb\data\log\MongoDB.log" --install --serviceName "MongoDB"

这里MongoDB.log就是开始建立的日志文件,--serviceName "MongoDB" 服务名为MongoDB

运行命令成功为如下图:

引时服务已经安装成功,运行

>NET START MongoDB   (开启服务)

>NET stop MongoDB   (关闭服务)

>

> C:\Program Files\mongodb\bin>mongod --dbpath "C:\Program Files\mongodb\data\db" --logpath "C:\Program Files\mongodb\data\log\MongoDB.log" --remove --serviceName "MongoDB"      (删除,注意不是--install了)

其它命令可查阅help命令或官网说明。

查看服务

运行bin文件夹下mongo.exe 客户端测试一下吧。测试同3.1相同 。

3.3 守护进程方式创

--fork 以守护进程方式运行MongoDB,创建服务器进程

>C:\Program Files\mongodb\bin>mongod --port 10220 --fork  --dbpath "C:\Program Files\mongodb\data\db" --logpath "C:\Program Files\mongodb\data\log\MongoDB.log"

forked process : 44086

all output going to : MongoDB.log

到此几种安装就介绍完了。

4、停止MongoDB

最稳妥的方式,处理完当前所有操作并将缓存的数据保存到磁盘上才停止

>user admin

>db.shutdownServer();

当然我们也可以直接关闭进程,但这种方式会导致缓存中的数据未急时刷新保存到磁盘上而丢失。

 

 

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=327101924&siteId=291194637