ODS Project--MONGODB using documentation

Source: Internet
Author: User

1. Start MongoDB:
#cd/srv/infra/mongodb/mongodb2.6.4/bin
#./mongod--dbpath=/mongodbdata/mongodb_db--port 27018--logpath=/mongodbdata/mongodb_logs/mongodb.log--logappend &

2. Close MongoDB:
[Email protected] mongodb]# MONGO
MongoDB Shell version:2.6.4
Connecting To:test

> Use admin
Switched to DB admin

> Db.shutdownserver ()

3. Restart
Delete Mongod.lock under/srv/infra/mongodb/mongodbdata/mongodb_db directory

#cd/srv/infra/mongodb/mongodb2.6.4/bin
#./mongod--dbpath=/mongodbdata/mongodb_db--port 27018--logpath=/mongodbdata/mongodb_logs/mongodb.log--logappend &

======================== Enter command line operation: ==============================================================

[Email protected] mongodb_db]# MONGO #进去命令行
MongoDB Shell version:2.6.4
Connecting To:test #默认连接到test库
> Show DBS #显示 all libraries
Admin (empty)
Local 0.078GB
Ods_mss 0.453GB
> Use ODS_MSS #连接到ods_mss库
Switched to DB ODS_MSS
> Show Tables #显示所有表
Custmessage
System.indexes
>



4. Create a table, delete a table


CREATE TABLE: Db.createcollection ("table_name")
Delete table: Db.table_name.drop ()
Conditional Delete: Db.table_name.remove ({' id ': ' 123 '})

5. Create an index, delete an index
Db. Table_name.ensureindex ({key:1})

The key here is to create an index in which 1 is the field name in ascending order. To create a descending index, you need to use-1.
For example: DB. Table_1.ensureindex ({"title": 1, "description":-1})

6. Find:
Db.table_name.find () #查所有
Db.table_name.find (). Pretty () #查所有, display by format
Db.table_name.find (). Count () #查总条数
Db.table_name.findOne () #查第一条


ODS Project--MONGODB using documentation

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.