Python3 using the MONGO database

Source: Internet
Author: User

1 initialization

After you create the database, you can type MONGO directly (if the port is the default 27017)

Use admin--Select Admin Database

Db.createuser ({User: ' admin ', pwd: ' admin123 ', roles: [{role: ' Root ', db: ' Admin '}]})

The user is then shown to be successfully added

2 Connecting the database

There are two ways to access the database afterwards

The first of these is:

1mongo 2use admin 3db.auth (' admin ', ' admin123 ')

The second type is

Mongo-u admin-p [Email protected]# 127.0.0.1/admin

I think it's the first way to remember something.

If you do not do this, your operation under the database will show no authorization

3 Adding and removing users

Db.createuser ({User: ' admin ', pwd: ' admin123 ', roles: [{role: ' Root ', db: ' admin '} '}) This is similar to the previous operation

User role has root read write ReadWrite

But must be under the corresponding database, or the operation is very cumbersome

4 Adding data

db.Hello.insert({name:‘World‘})

db.Hello.find()

Python3 using the MONGO database

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.