Home Database Mysql Tutorial 第一节 MongoDB介绍及下载与安装

第一节 MongoDB介绍及下载与安装

Jun 07, 2016 pm 05:38 PM
mongodb download introduce Install

引言 MongoDB是一个介于关系数据库和非关系数据库之间的产品,是非关系数据库当中功能最丰富,最像关系数据库的。他支持的数据结构非常松散,是类似json的bjson格式,因此可以存储比较复杂的数据类型。Mongo最大的特点是他支持的查询语言非常强大,其语法有

引言

    MongoDB是一个介于关系数据库和非关系数据库之间的产品,是非关系数据库当中功能最丰富,最像关系数据库的。他支持的数据结构非常松散,是类似json的bjson格式,因此可以存储比较复杂的数据类型。Mongo最大的特点是他支持的查询语言非常强大,其语法有点类似于面向对象的查询语言,几乎可以实现类似关系数据库单表查询的绝大部分功能,而且还支持对数据建立索引。

它的特点是高性能、易部署、易使用,存储数据非常方便。主要功能特性有:

所谓“面向集合”(Collenction-Orented),意思是数据被分组存储在数据集中,被称为一个集合(Collenction)。每个 集合在数据库中都有一个唯一的标识名,,并且可以包含无限数目的文档。集合的概念类似关系型数据库(RDBMS)里的表(table),不同的是它不需要定 义任何模式(schema)。 模式自由(schema-free),意味着对于存储在mongodb数据库中的文件,我们不需要知道它的任何结构定义。如果需要的话,你完全可以把不同结构的文件存储在同一个数据库里。 存储在集合中的文档,被存储为键-值对的形式。键用于唯一标识一个文档,为字符串类型,而值则可以是各中复杂的文件类型。我们称这种存储形式为BSON(Binary Serialized dOcument Format)。

MongoDB服务端可运行在Linux、Windows或OS X平台,支持32位和64位应用,默认端口为27017。推荐运行在64位平台,因为MongoDB

在32位模式运行时支持的最大文件尺寸为2GB。

MongoDB把数据存储在文件中(默认路径为:/data/db),为提高效率使用内存映射文件进行管理。

以上为随便摘的,其实就是非传统的非关系数据库,现在归到文档型数据库分类之中,注意32位操作系统支持的最大文件为2GB,所以做大文件海量储存的朋友要选择64位的系统安装。开始我们的下载安装之路吧。

一、下载

MongoDB的官网是:

MongoDB最新版本下载在官网的DownLoad菜单下: 

本人选择的是Windows 32-bit 1.8.1版本

MongoDB For .net 驱动开发包位于官网的Driver菜单下(含其它语言开发链接):https://github.com/mongodb/mongo-csharp-driver/downloads

本人操作系统为Windows7 专业版,选择MongoDB版本为Windows 32-bit 1.8.1,开发包为VS2008版本

开始我们的安装过程了

二、安装

1.解压mongodb-win32-i386-1.8.1.zip ,创建路径C:\Program Files\mongodb ,将解压后的Bin文件Copy to 此文件夹下

2.C:\Program Files\mongodb 下建立Data文件夹 C:\Program Files\mongodb\data ,然后分别建立db,log两个文件夹,至此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();

当然我们也可以直接关闭进程,但这种方式会导致缓存中的数据未急时刷新保存到磁盘上而丢失。下一章就是mongo for .net开发了。

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
2 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Repo: How To Revive Teammates
1 months ago By 尊渡假赌尊渡假赌尊渡假赌
Hello Kitty Island Adventure: How To Get Giant Seeds
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Introduction to how to download and install the superpeople game Introduction to how to download and install the superpeople game Mar 30, 2024 pm 04:01 PM

The superpeople game can be downloaded through the steam client. The size of this game is about 28G. It usually takes one and a half hours to download and install. Here is a specific download and installation tutorial for you! New method to apply for global closed testing 1) Search for "SUPERPEOPLE" in the Steam store (steam client download) 2) Click "Request access to SUPERPEOPLE closed testing" at the bottom of the "SUPERPEOPLE" store page 3) After clicking the request access button, The "SUPERPEOPLECBT" game can be confirmed in the Steam library 4) Click the install button in "SUPERPEOPLECBT" and download

Which version is generally used for mongodb? Which version is generally used for mongodb? Apr 07, 2024 pm 05:48 PM

It is recommended to use the latest version of MongoDB (currently 5.0) as it provides the latest features and improvements. When selecting a version, you need to consider functional requirements, compatibility, stability, and community support. For example, the latest version has features such as transactions and aggregation pipeline optimization. Make sure the version is compatible with the application. For production environments, choose the long-term support version. The latest version has more active community support.

How to download Beilehu children's songs How to download Beilehu children's songs Mar 28, 2024 am 11:10 AM

As an indispensable accompaniment to children's growth, Beilehu's children's songs have won the love of countless parents and children with their cheerful melody, vivid pictures and entertaining and educational content. In order to allow babies to enjoy the joy brought by children's songs anytime and anywhere, many parents hope to download Beilehu's children's songs to their mobile phones or tablets so that they can listen to their children at any time, but how to save Beilehu's children's songs? On your mobile phone, this tutorial will bring you a detailed introduction. Users who don’t understand it yet can come and read along with this article to learn more. Beilehu Nursery Rhymes Download Children's Songs Multi-Picture Tutorial: Open the software and select a children's song you want to download. The editor takes "Classic Children's Songs" as an example. 2. Click the "Download" button below the children's song star.

The difference between nodejs and vuejs The difference between nodejs and vuejs Apr 21, 2024 am 04:17 AM

Node.js is a server-side JavaScript runtime, while Vue.js is a client-side JavaScript framework for creating interactive user interfaces. Node.js is used for server-side development, such as back-end service API development and data processing, while Vue.js is used for client-side development, such as single-page applications and responsive user interfaces.

Where is the database created by mongodb? Where is the database created by mongodb? Apr 07, 2024 pm 05:39 PM

The data of the MongoDB database is stored in the specified data directory, which can be located in the local file system, network file system or cloud storage. The specific location is as follows: Local file system: The default path is Linux/macOS:/data/db, Windows: C:\data\db. Network file system: The path depends on the file system. Cloud Storage: The path is determined by the cloud storage provider.

How to download Kugou Music to your local computer. Tutorial on how to download Kugou Music to your local computer. How to download Kugou Music to your local computer. Tutorial on how to download Kugou Music to your local computer. Mar 28, 2024 pm 01:20 PM

Kugou Music can help us relieve boredom in our daily life. We can listen to many good songs, especially some songs in film and television variety shows. As long as we look for them, they will appear and everyone can listen to them. How do we download the songs we like to listen to locally? Many friends don’t know, so the editor has simply compiled a guide for downloading songs to the local computer for those who are interested. Let's come to this website to check out this guide. I hope it will be helpful to everyone. Tutorial for downloading Kugou Music to your local computer 1. First open Kugou Music and click on the music you want to download on the Kugou Music page; 2. Then enter the page of this music and click on the [three-dot icon] in the lower right corner ; 3. After clicking

What are the advantages of mongodb database What are the advantages of mongodb database Apr 07, 2024 pm 05:21 PM

The MongoDB database is known for its flexibility, scalability, and high performance. Its advantages include: a document data model that allows data to be stored in a flexible and unstructured way. Horizontal scalability to multiple servers via sharding. Query flexibility, supporting complex queries and aggregation operations. Data replication and fault tolerance ensure data redundancy and high availability. JSON support for easy integration with front-end applications. High performance for fast response even when processing large amounts of data. Open source, customizable and free to use.

What does mongodb mean? What does mongodb mean? Apr 07, 2024 pm 05:57 PM

MongoDB is a document-oriented, distributed database system used to store and manage large amounts of structured and unstructured data. Its core concepts include document storage and distribution, and its main features include dynamic schema, indexing, aggregation, map-reduce and replication. It is widely used in content management systems, e-commerce platforms, social media websites, IoT applications, and mobile application development.

See all articles