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

Introduction and use of triggers and cursors in MySQL

Trigger Introduction A trigger is a special store...

Tutorial on processing static resources in Tomcat

Preface All requests in Tomcat are handled by Ser...

Detailed explanation of the marquee attribute in HTML

This tag is not part of HTML3.2 and is only suppo...

How to implement the King of Glory matching personnel loading page with CSS3

Those who have played King of Glory should be fam...

How to package the uniapp project as a desktop application

Installing Electron cnpm install electron -g Inst...

Solution to the problem that the docker container cannot be stopped

The solution is as follows: 1. Force delete conta...

Detailed tutorial for installing ffmpeg under Linux

1. Install ffmpeg under centos linux 1. Download ...

Detailed steps to install nginx on Apple M1 chip and deploy vue project

brew install nginx Apple Mac uses brew to install...

Nginx implements https website configuration code example

https base port 443. It is used for something cal...

How to redirect URL using nginx rewrite

I often need to change nginx configuration at wor...

How to fix the footer at the bottom of the page (multiple methods)

As a front-end Web engineer, you must have encoun...

How to install nginx under Linux

Nginx is developed in C language and is recommend...

How to use axios request in Vue project

Table of contents 1. Installation 2. There is no ...