MongoDB(二)安装配置了解
前边介绍了MongoDB的大概理论知识,这篇来对MongoDB进行一下安装使用,支持安装在windows和linux上,当然了更多情况下我们是安装在linux上,因为毕竟服务器用linux的还是主流,当然了对于不同的系统,MongoDB的安装使用等其实都基本相同的,所以不用太在意这
前边介绍了MongoDB的大概理论知识,这篇来对MongoDB进行一下安装使用,支持安装在windows和linux上,当然了更多情况下我们是安装在linux上,因为毕竟服务器用linux的还是主流,当然了对于不同的系统,MongoDB的安装使用等其实都基本相同的,所以不用太在意这个,我们学习在那个平台上都是可以的。好,下载MongoDB:http://www.mongodb.org/downloads,根据我们的需要进行安装。
1,解压安装:将下载好的MongoDB解压到想要安装的路径下即可,例如:d:\mongodb
2,建文件夹:建立数据存放文件夹,例如:d:\mongodb\data\db;建立日志存放文件夹,例如:d:\mongodb\log\mongodb.log。(根据实际情况而定,不是固定的,只要有存放数据和日志的文件夹即可)
3,Win+R进入“运行”输入cmd,进入dos窗口,cd命令进入d:\mongodb\bin下,然后运行:mongod --dbpath"d:\mongodb\data\db\" --logpath "d:\mongodb\log\mongodb.log,即可运行mongodb服务。注意,mongod,dbpath,logpath几个关键字。这里我们都可以查看bin下的命令,我们用的都是这些,通过“命令-help”进行查看其参数即可。
4,进入数据库:mongodb的默认端口是27017,直接使用mongo命令即可进入数据库。然后进行各种database,collection,document进行增删改查的操作。但是这里的命令窗口不能关闭,要不mongodb的服务将停止。
5,让服务随电脑启动一起启动,在dos窗口中输入:
mongod --dbpath "d:\mongodb\data\db" --logpath"d:\mongodb\data\log\mongodb.log" --install --serviceName"MongoDB"
英文翻译也可以看出,是将这个启动mongodb的服务命令,加载到电脑服务中,服务名字叫做"MongoDB"。
然后启动即可:NET START MongoDB
6,关闭MongoDB服务,并关闭随机启动:
NET stop MongoDB (关闭服务)
mongod --dbpath"d:\mongodb\data\db" --logpath "d:\mongodb\data\log\mongodb.log" --remove--serviceName "MongoDB"
好,这样就算基本完成了,当然linux中和这也是一样的,最起码bin下的命令是通用的,需要我们的是掌握一些linux的操作命令才行。
看一下常用命令:
- show dbs 显示数据库列表
- use dbname 进入dbname数据库,大小写敏感,没有这个数据库也不要紧
- show collections 显示数据库中的集合,相当于表格
对于数据库的增删改查及其命令,下篇简单介绍。剩下简单看一下MongoDB的体系架构,看一张图吧,感觉挺清楚明了:
喎?http://www.2cto.com/kf/ware/vc/" target="_blank" class="keylink">vcD48cD4gICAgwO+x37/J0tS05rXEyv2+3cDg0M2jujwvcD48dWwgdHlwZT0="disc">
- null null用于表示空值或者不存在的字段。 {"x":null}
- 布尔 布尔类型有两个值'true'和'false1'. {"X":true}
- 32位整数 类型不可用。JavaScript仅支持64位浮点数,所以32位整数会被自动转换。
- 64位整数 不支持这个类型。shell会使用一个特殊的内嵌文档来显示64位整数,
- 64位浮点数 shell中的数字都是这种类型。下面的表示都是浮点数: {"X" : 3.1415926} {"X" : 3}
- 字符串 UTF-8字符串都可表示为字符串类型的数据: {"x" : "foobar"}
- 符号 不支持这种类型。shell将数据库里的符号类型转换成字符串。
- 对象id 对象id是文档的12字节的唯一 ID, {"X" :ObjectId() }
- 日期 日期类型存储的是从标准纪元开始的毫秒数。不存储时区: {"X" : new Date()}
- 正则表达式 文档中可以包含正则表达式,采用JavaScript的正则表达式语法: {"x" : /foobar/i}
- 代码 文档中还可以包含JavaScript代码:{"x" : function() { /* …… */ }}
- 二进制数据 二进制数据可以由任意字节的串组成。不过shell中无法使用。
- 最大值 BSON包括一个特殊类型,表示可能的最大值。shell中没有这个类型。
- 最小值 BSON包括一个特殊类型,表示可能的最小值。shell中没有这个类型。
- 未定义 文档中也可以使用未定义类型:{"x":undefined}
- 数组 值的集合或者列表可以表示成数组:{"x" : ["a", "b", "c"]}
- 内嵌文档 文档可以包含别的文档,也可以作为值嵌入到父文档中,数据可以组织得更自然些,不用非得存成扁平结构的:{"x" : {"food" : "noodle"}}
当然了,为了更加方便的操作MongoDB,也提供了类似PL/SQLdeveloper(连接Oracle),Mysql Front,Navicat Premium 等连接数据库的工具,这里看下MongoVUE,很是不错,看一下界面:
好,剩下我们就按照数据库思路学习把,什么增删改查,什么分布,负载均衡等等,看后边的总结。

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

This article introduces how to configure MongoDB on Debian system to achieve automatic expansion. The main steps include setting up the MongoDB replica set and disk space monitoring. 1. MongoDB installation First, make sure that MongoDB is installed on the Debian system. Install using the following command: sudoaptupdatesudoaptinstall-ymongodb-org 2. Configuring MongoDB replica set MongoDB replica set ensures high availability and data redundancy, which is the basis for achieving automatic capacity expansion. Start MongoDB service: sudosystemctlstartmongodsudosys

When developing an e-commerce website, I encountered a difficult problem: how to provide users with personalized product recommendations. Initially, I tried some simple recommendation algorithms, but the results were not ideal, and user satisfaction was also affected. In order to improve the accuracy and efficiency of the recommendation system, I decided to adopt a more professional solution. Finally, I installed andres-montanez/recommendations-bundle through Composer, which not only solved my problem, but also greatly improved the performance of the recommendation system. You can learn composer through the following address:

This article describes how to build a highly available MongoDB database on a Debian system. We will explore multiple ways to ensure data security and services continue to operate. Key strategy: ReplicaSet: ReplicaSet: Use replicasets to achieve data redundancy and automatic failover. When a master node fails, the replica set will automatically elect a new master node to ensure the continuous availability of the service. Data backup and recovery: Regularly use the mongodump command to backup the database and formulate effective recovery strategies to deal with the risk of data loss. Monitoring and Alarms: Deploy monitoring tools (such as Prometheus, Grafana) to monitor the running status of MongoDB in real time, and

It is impossible to view MongoDB password directly through Navicat because it is stored as hash values. How to retrieve lost passwords: 1. Reset passwords; 2. Check configuration files (may contain hash values); 3. Check codes (may hardcode passwords).

Detailed explanation of MongoDB efficient backup strategy under CentOS system This article will introduce in detail the various strategies for implementing MongoDB backup on CentOS system to ensure data security and business continuity. We will cover manual backups, timed backups, automated script backups, and backup methods in Docker container environments, and provide best practices for backup file management. Manual backup: Use the mongodump command to perform manual full backup, for example: mongodump-hlocalhost:27017-u username-p password-d database name-o/backup directory This command will export the data and metadata of the specified database to the specified backup directory.

GitLab Database Deployment Guide on CentOS System Selecting the right database is a key step in successfully deploying GitLab. GitLab is compatible with a variety of databases, including MySQL, PostgreSQL, and MongoDB. This article will explain in detail how to select and configure these databases. Database selection recommendation MySQL: a widely used relational database management system (RDBMS), with stable performance and suitable for most GitLab deployment scenarios. PostgreSQL: Powerful open source RDBMS, supports complex queries and advanced features, suitable for handling large data sets. MongoDB: Popular NoSQL database, good at handling sea

PiNetwork is about to launch PiBank, a revolutionary mobile banking platform! PiNetwork today released a major update on Elmahrosa (Face) PIMISRBank, referred to as PiBank, which perfectly integrates traditional banking services with PiNetwork cryptocurrency functions to realize the atomic exchange of fiat currencies and cryptocurrencies (supports the swap between fiat currencies such as the US dollar, euro, and Indonesian rupiah with cryptocurrencies such as PiCoin, USDT, and USDC). What is the charm of PiBank? Let's find out! PiBank's main functions: One-stop management of bank accounts and cryptocurrency assets. Support real-time transactions and adopt biospecies

MongoDB and relational database: In-depth comparison This article will explore in-depth the differences between NoSQL database MongoDB and traditional relational databases (such as MySQL and SQLServer). Relational databases use table structures of rows and columns to organize data, while MongoDB uses flexible document-oriented models to better suit the needs of modern applications. Mainly differentiates data structures: Relational databases use predefined schema tables to store data, and relationships between tables are established through primary keys and foreign keys; MongoDB uses JSON-like BSON documents to store them in a collection, and each document structure can be independently changed to achieve pattern-free design. Architectural design: Relational databases need to pre-defined fixed schema; MongoDB supports
