MongoDB Note 1

Source: Internet
Author: User

Reference Links:

https://docs.mongodb.com/manual/reference/method/db.createUser/#create-administrative-user-with-roles

    1. Installing MongoDB under Linux

Download:

Curl-o https://fastdl.mongodb.org/linux/mongodb-linux-x86_64-3.0.6.tgz

Extract:

TAR-ZXVF mongodb-linux-x86_64-3.0.6.tgz

Copy the unpacked package to the specified directory:

MV mongodb-linux-x86_64-3.0.6//usr/local/mongodb


MongoDB's executable file is located in the bin directory, so you can add it to your path path:

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

Create a database directory

Mkdir-p/data/db

MongoDB provides a simple HTTP user interface. If you want to enable this feature, you need to specify the parameter--rest at boot time.

Mongod--dbpath=/data/db--rest


2. Create an administrator user

Db.createuser (

{

User: "AppAdmin",

PWD: "Password",

Roles

[

{role: "ReadWrite", db: "Config"},

"Clusteradmin"

]

}

)


3. Create a user with a role

Db.createuser (

{

User: "Accurme",

PWD: "Accurme",

roles:["ReadWrite", "DbAdmin"]

})


4. Connection database-uri connection syntax:

Mongodb://[username:[email protected]]host1[:p ort1][,host2[:p Ort2],... [, hostn[:p Ortn]] [/[database][?options]]

mongodb://this is a fixed format that must be specified.

Username:[email protected] option, if set, after connecting to the database server, the driver will attempt to log into this database

Host1 must specify at least one host, and Host1 is the only URI to be filled in. It specifies the address to connect to the server. If you are connecting to a replica set, specify multiple host addresses.

Portx Optional specified port, if not, default is 27017

/database If you specify Username:[email protected], connect and verify the login to the specified database. If not specified, the test database is opened by default.

The options is the connection option. If you do not use/database, you need to add/. All connection options are key-value pairs Name=value, and key-value pairs are separated by & or; (semicolon)


Mongodb://example:[email Protected]:27017/accurme


5. Create a database

Use database_name;


6. View all databases

Show DBS;


7. Deleting a database

Use test

Db.dropdatabase ()


8. View collections in the Database (table)

Show tables;


9. Deleting a collection in a database (table)

Deleted the collection from the Runoob database site

Use Runoob

Db.site.drop ()





MongoDB Note 1

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.