MongoDB Database Usage Summary

Source: Internet
Author: User
Tags auth install mongodb

0. Install MongoDB:

1) Curl-o http://downloads.mongodb.org/linux/mongodb-linux-x86_64-2.6.4.tgz

2) TAR-ZXVF mongodb-linux-x86_64-2.6.4.tgz

3) Mkdir-p MongoDB

Cp-r Mongodb-linux-x86_64-2.6.4/mongodb

4) Export Path=<mongodb-install-directory>/bin: $PATH


    1. Mongod--dbpath=/home/app/mongodb/mongodbdata/--Logpath=/home/app/mongodb/log/mongodb.log--logappend&

2.mongo

3.use Admin

4.db.adduser (' Mongouser ', ' 123456! ');

5.kill

6.mongod--auth--dbpath=/home/app/mongodb/mongodbdata/--

Logpath=/home/app/mongodb/log/mongodb.log--logappend&

7. Create a database Operationlog, create a collections

Operationlog,

Oparticlelog,

Optopiclog,

Oploginlog

8. Create an index:

Db.operationlog.ensureIndex ({"UserId": 1, "UpdateTime":-1},{"name": "Oplog_userid_index"});


Db.oparticlelog.ensureIndex ({"UserId": 1, "UpdateTime":-1},{"name": "Opdoclog_userid_index"});

Db.oparticlelog.ensureIndex ({"ArticleID": 1, "UpdateTime":-1},{"name": "Opdoclog_docid_index"});

Db.oploginlog.ensureIndex ({"UserId": 1, "UpdateTime":-1},{"name": "Oploginlog_userid_index"});

Db.optopiclog.ensureIndex ({"UserId": 1, "UpdateTime":-1},{"name": "Optopicid_userid_index"});

Db.optopiclog.ensureIndex ({"TopicID": 1, "UpdateTime":-1},{"name": "Optopicidlog_topicid_index"});

9. Add users to Operationlog,

1) MONGO

2) Use admin;

3) Db.auth (' Mongouser ', ' 123456! ');

4) Use Operationlog

5) Db.adduser (' Mongouser ', ' 123456! ');


10. Other Commands:

Mongo

Use Operationlog;

Db.auth (' Mongouser ', ' 123456! ');

Show DBS: Display Database list

Show Collections: Displays a collection in the current database (similar to a table in a relational database)

Show Users: Show user

Db.optopiclog.count (); View Collection Total data volume

Exit Exit

11. View the Delete log feature:

Mongo

Use Operationlog;

Db.auth (' Mongouser ', ' 123456! ');

1) CREATE TABLE: Db.createcollection ("Opdellog");

2) Create an index:

Db.opdellog.ensureIndex ({"UserId": 1, "UpdateTime":-1},{"name": "Opdellog_userid_index"});

Db.opdellog.ensureIndex ({"ArticleID": 1, "UpdateTime":-1},{"name": "Opdellog_docid_index"});

Db.opdellog.ensureIndex ({"Articleormodelname": 1, "UpdateTime":-1},{"name": "Opdellog_docname_index"});

3) View all indexes on a table

Db.opdellog.getIndexes ();


This article from "Quiet Zhiyuan" blog, declined reprint!

MongoDB Database Usage Summary

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.