Mongo DB Command Introduction

Source: Internet
Author: User
Tags create index create database

Introduction recently in learning MongoDB summed up some commands and commonly used things to do the collation of common directory files

 

    mongod 数据库部署命令

    mongo 连接mongodb数据库而使用的命令

    mongoimport mongodb 的导入功能

    mongoexport mongodb 的导出功能

    mongorestore mongodb 的二进制导入功能,一般用作数据库恢复与备份

    mongodumpp mongodb 的二进制导出功能,一般用作数据库恢复与备份

    mongostat 查看mongodb 的各种状态

Introduction to the executable command 1. Start MongoDB first to specify the MONGO data directory and log file path data directory such as:/data/db/log file such as:/usr/local/var/log/mongodb/mongo.log Start command:
The #--fork option will notify Mongod to run     in the background 27017 --dbpath/data/db/--logpath/usr/local/var/log/ Mongodb/mongo.log--fork    #使用& background start        27017 --dbpath/data/db/--logpath/usr/ local/var/log/mongodb/mongo.log &

2. configuration file Configuration

$ vim/usr/local/etc/mongod.conf    Port=10001 "represents the port number and defaults to 27017 if not specified      "         dbpath=/data/db/  "database path"         logpath=/usr/local/var/log/mongodb/  Mongo.log  "Log path"          logappend=true  /usr/local/etc/-F mongodb.conf

3. Close

> Db.shuidownserver ()
About MongoDB Common commands
# View current system all databases $ show DBS # Switch database and automatically create database $ use local # Delete database $ db.dropdatabase () # Insert data, insert has a parameter, format-qualified JSON $ db.local_collection.insert ({x:1}) # View created table $ show Collections # Data query, accept a parameter, JSON format query condition is empty return all data # Skip: First few start query # limit: return How many data # Sort: Sort $ db.local_collection.find ({x:1}). Skip (3). Limit (2). Sort ({x:1}) # Update data $ db.local_collection.update ({x:1}, {x:999}) # only modifies X's data, other properties remain unchanged $ db.local_collection.update ({x:1}, {$Set: {x:999}}) # If the data you are looking for does not exist, a $ db.local_collection.update is automatically written ({x:1}, {$Set: {x:999}},true# Update multiple data $ db.local_collection.update ({x:1}, {$Set: {x:999}},false,true# To delete data, you must pass the parameter $ db.local_collection.remove ({x:1}) # Delete data table $ db.local_collection.drop () # View all data tables $ show Tables # View index $ db.local_coll Ection.getindexes () # CREATE INDEX $ db.local_collection.ensureIndex ({x:1})

Summary

This article is only used as a reference for getting started notes, and later MongoDB knowledge LZ will be added, 3q~

Mongo DB Command Introduction

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.