Docker connection mongodb implementation process and code examples

Docker connection mongodb implementation process and code examples

After the container is started

Log in to admin first and create a new user

$ docker exec -it mongo mongo admin
# Create a user named admin with a password of 123456.
>db.createUser({user:"duser",pwd:"test1mongodb23","roles" : [{"role" : "dbAdmin","db" : "cpeducloud2"},
{"role" : "dbOwner","db" : "cpeducloud2"},{"role" : "readWrite","db" : "cpeducloud2"},
{"role" : "userAdmin","db" : "cpeducloud2"}],"mechanisms" : ["SCRAM-SHA-1","SCRAM-SHA-256"]});

 # Try to connect using the user information created above.

> db.auth('duser', 'test1mongodb23')

The creation is successful here, so create a new library and account here (note that this is the case of admin login)

For example, the library created here is sboot,

After creating the user, log out and log in again with the new user in the new database (sboot)

The above is the full content of this article. I hope it will be helpful for everyone’s study. I also hope that everyone will support 123WORDPRESS.COM.

You may also be interested in:
  • Docker builds cluster MongoDB implementation steps
  • How to install the latest version of MongoDB using Docker
  • Springboot integrates MongoDB Docker development tutorial
  • Docker container deployment attempt - multi-container communication (node+mongoDB+nginx)
  • Implementation code for using mongodb database in Docker
  • How to use MongoDB to store Docker logs
  • Detailed explanation of using mongodb database in docker (access in LAN)
  • Method for implementing authorized access to MongoDB based on Docker

<<:  JS Difficulties Synchronous and Asynchronous and Scope and Closure and Detailed Explanation of Prototype and Prototype Chain

>>:  MySQL bypasses granting information_schema objects and reports ERROR 1044 (4200) error

Recommend

React gets input value and submits 2 methods examples

Method 1: Use the target event attribute of the E...

React native realizes the monitoring gesture up and down pull effect

React native implements the monitoring gesture to...

JS thoroughly understands GMT and UTC time zones

Table of contents Preface 1. GMT What is GMT Hist...

Detailed explanation of Nginx proxy_redirect usage

Today, I encountered a little problem when I was ...

Understand the use of CSS3's all attribute

1. Compatibility As shown below: The compatibilit...

Implementation example of scan code payment in vue project (with demo)

Table of contents Demand background Thought Analy...

Use Rem layout to achieve adaptive

I have written an article about mobile adaptation...

Implementation of Grid common layout

No gaps on both sides, gaps between each column w...

How to change the host name in Linux

1. View the current host name [root@fangjian ~]# ...

CSS setting div background image implementation code

Adding background image control to a component re...

Implementation steps for enabling docker remote service link on cloud centos

Here we introduce the centos server with docker i...

MySQL password is correct but cannot log in locally -1045

MySQL password is correct but cannot log in local...

Use of Linux ifconfig command

1. Command Introduction The ifconfig (configure a...