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