Database MongoDB 3.6 Installation, single-machine multi-instance, and basic operations with big data prerequisites

Source: Internet
Author: User
Tags install mongodb mongodb mongodb server

MONGDB Introduction MongoDB is a database based on distributed file storage. Written by the C + + language. Designed to provide scalable, high-performance data storage solutions for Web applications. MongoDB is a product between a relational database and a non-relational database, and is the most versatile and most like relational database in a non-relational database. The data structure it supports is very loose and is a JSON-like Bson format, so you can store more complex data types. The most important feature of MONGO is that its supported query language is very powerful, its syntax is somewhat similar to object-oriented query language, almost can implement similar relational database single table query of most functions, but also support the indexing of data. MongoDB Features
    • High performance, easy to deploy, easy to use, easy to store data.
    • For collection storage, easy to store data for object types.

    • Mode of freedom.

    • Supports dynamic queries.

    • Supports full indexes, including internal objects.

    • Support Queries.

    • Supports replication and recovery.

    • Use efficient binary data storage, including large objects such as video.

    • Automatically handles fragmentation to support scalability at the cloud level.

    • Supports multiple languages such as ruby,python,java,c++,php,c#.

    • The file storage format is Bson (an extension of JSON).

    • can be accessed over the network. Environment: Operating system: CentOS 7.3 x86_64 installation mongodb:1. Configure the Yum source repository:
vim /etc/yum.repos.d/mongodb-org.repo[mongodb-org]name=MongoDB Repositorybaseurl=https://repo.mongodb.org/yum/redhat/$releasever/mongodb-org/3.6/x86_64/gpgcheck=1enabled=1gpgkey=https://www.mongodb.org/static/pgp/server-3.6.as
2. Install MongoDB:
yum  install -y mongodb-orgsystemctl start mongod.service     #开启服务
systemctl start mongod.service     #开启服务
[[email protected] ~]# mongo          #进入数据库MongoDB shell version v3.6.6connecting to: mongodb://127.0.0.1:27017MongoDB server version: 3.6.6
Configure MongoDB Standalone Multi-instance 1. To copy a MongoDB configuration file:
cp -p /etc/mongod.conf /etc/mongod2.confvim /etc/mongodb2.confsystemLog:  destination: file  logAppend: true  path: /data/logs/mongod2.log      #日志文件位置.....storage:  dbPath: /data/mongodb/mongodb2    #数据文件位置  journal:......net:  port: 27018                      #修改端口号  
mkdir -p /data/mongodb/mongodb2   #创建数据文件位置mkdir -p /data/logs/              #创建日志文件位置touch /data/logs/mongodb2.log     #创建日志文件chmod -R 777 /data/logs/mongodb2.log  #添加日志文件的权限
[[email protected] ~]# mongod -f /etc/mongod2.conf     #开启实例about to fork child process, waiting until server is ready for connections.forked process: 23824child process started successfully, parent exiting
[[email protected] ~]# mongo --port 27018    #进入实例MongoDB shell version v3.6.6connecting to: mongodb://127.0.0.1:27018/MongoDB server version: 3.6.6
[[email protected] ~]# mongod -f /etc/mongod2.conf --shutdown   #关闭实例killing process with pid: 23824
MongoDB Basic Operations
Operation Description
Show DBS View the list of databases under the current instance
Show Users Show Users
Use <db_name> Toggle the current database
Db.help () Show Database Operations Command
Show collections Displays the current database collection
Db.foo.help () Show collection Operations Command, Foo is a collection under the current database
Db.foo.find () Data lookup for the Foo collection in the current database
    • Creating and Deleting databases
format: Use database_name #切换数据库如果有切换, not created
mongos> use abcswitched to db abc
format: db.dropdatabase () #删除数据库
mongos> use abcswitched to db abcmongos> db.dropDatabase(){ "info" : "database does not exist", "ok" : 1 }
    • Inserting data, deleting data, and modifying data
mongos> db.test.insert({"id":1,"name":"zhangsan"})     #在test集合插入数据  没有test集合默认会自动创建WriteResult({ "nInserted" : 1 })mongos> db.test.insert({"id":2,"name":"lisi"})WriteResult({ "nInserted" : 1 })mongos> db.test.find()                             #查看集合内容{ "_id" : ObjectId("5b4eb95659122739e2695613"), "id" : 1, "name" : "zhangsan" }{ "_id" : ObjectId("5b4eb96759122739e2695614"), "id" : 2, "name" : "lisi" }mongos> db.test.remove({"id":1})        #删除test集合中的id为1的数据WriteResult({ "nRemoved" : 1 })mongos> db.test.find(){ "_id" : ObjectId("5b4eb96759122739e2695614"), "id" : 2, "name" : "lisi" }mongos> db.test.update({"id":2},{$set:{"name":"wangwu"}})    #修改数据WriteResult({ "nMatched" : 1, "nUpserted" : 0, "nModified" : 1 })mongos> db.test.find(){ "_id" : ObjectId("5b4eb96759122739e2695614"), "id" : 2, "name" : "wangwu" }
    • Import and export of data
[[email protected] bin]# ./mongoexport -d abc -c test -o /opt/test.json  #导出文件格式为json2018-07-18T12:07:50.297+0800    connected to: localhost2018-07-18T12:07:50.299+0800    exported 2 records [[email protected] bin]# ./mongoimport -d abc -c test --file test.json    #导入数据库2018-07-18T12:09:09.880+0800    Failed: open test.json: no such file or directory2018-07-18T12:09:09.881+0800    imported 0 documents
Parameter description
    • -D: Indicates the name of the database
    • -C: Indicates the name of the collection
    • -O: Indicates the file name to export

Database MongoDB 3.6 Installation, single-machine multi-instance, and basic operations with big data prerequisites

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.