当前位置:网站首页>Mongo from start to installation and problems encountered
Mongo from start to installation and problems encountered
2022-07-24 03:48:00 【Struggling youth, come on】
problem 1. To build database
use xxx
When there is xxx When I was in the library , Do not create a new , When there is no xxx When , Automatically create xxx database
use book
The new data
db.book.insert({"name":"cjn","age":24,"sex":" male "});When performing , error
here
MongoDB When operating , appear
db.dropDatabase()
{
"ok" : 0,
"errmsg" : "not authorized on runoob to execute command { dropDatabase: 1.0, writeConcern: { w: \"majority\", wtimeout: 600000.0 }, lsid: { id: UUID(\"24c2cedc-ec83-4d78-88f3-0d10fa35ce9d\") }, $db: \"runoob\" }",
"code" : 13,
"codeName" : "Unauthorized"
}This tip
No permissions , Then add users quickly
Switch to admin library
use admin;
Add users
db.createUser( {
user: "sa",
pwd: "sa",
roles: [ { role: "root", db: "admin" } ]
});
Now that you have added users
use sa To login
db.auth('sa','sa');And then in
db.book.insert({"name":"cjn","age":24,"sex":" male "});success !
use runoob
switched to db runoob
> db.dropDatabase()
{
"ok" : 0,
"errmsg" : "not authorized on runoob to execute command { dropDatabase: 1.0, writeConcern: { w: \"majority\", wtimeout: 600000.0 }, lsid: { id: UUID(\"24c2cedc-ec83-4d78-88f3-0d10fa35ce9d\") }, $db: \"runoob\" }",
"code" : 13,
"codeName" : "Unauthorized"
}
> use admin
switched to db admin
> db.createUser( {
... user: "sa",
... pwd: "sa",
... roles: [ { role: "root", db: "admin" } ]
... });
Successfully added user: {
"user" : "sa",
"roles" : [
{
"role" : "root",
"db" : "admin"
}
]
}
> db.auth('sa','sa');
1
> db.book.insert({"name":"cjn","age":24,"sex":" male "});
uncaught exception: SyntaxError: illegal character :
@(shell):1:49
> use runoob
switched to db runoob
> db
runoob
> show dbs
admin 0.000GB
config 0.000GB
local 0.000GB
runoob 0.000GB
> use runoob
switched to db runoob
> db.dropDatabase()
{ "ok" : 1 }
> show dbs
admin 0.000GB
config 0.000GB
local 0.000GB
> use runoob
switched to db runoob
> show dbs
admin 0.000GB
config 0.000GB
local 0.000GB
> db.runoob.insert({"name":" Novice tutorial "})
WriteResult({ "nInserted" : 1 })
> show dbs
admin 0.000GB
config 0.000GB
local 0.000GB
runoob 0.000GB
> use runoob
switched to db runoob
> db.dropDatabase()
{ "ok" : 1 }
> show dbs
admin 0.000GB
config 0.000GB
local 0.000GB
> use runoob
switched to db runoob
> db.createCollection("runoob")
{ "ok" : 1 }
> show tables
runoob
> db.runoob.drop()
true
> show tables
>
docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
ssh shell
kex_exchange_identification: Connection closed by remote host
Connection closed by 127.0.0.1 port 7890
docker run -idt mongo /bin/bash
docker images
docker ps -a
docker exec -it be59694ff787 /bin/bash
mongo
MongoDB shell version v5.0.9
connecting to: mongodb://127.0.0.1:27017/?compressors=disabled&gssapiServiceName=mongodb
Error: couldn't connect to server 127.0.0.1:27017, connection attempt failed: SocketException: Error connecting to 127.0.0.1:27017 :: caused by :: Connection refused :
[email protected]/mongo/shell/mongo.js:372:17
@(connect):2:6
exception: connect failed
exiting with code 1
[email protected]:/# mongod
ls
exit
docker stop be
docker start be
docker exec -it be /bin/bash
cd
ls
exit
docker search mongo
docker run -itd --name mongo -p 27017:27017 mongo --auth
docker exec -it mongo mongo admin
MongoDB shell version v5.0.9
connecting to: mongodb://127.0.0.1:27017/admin?compressors=disabled&gssapiServiceName=mongodb
Implicit session: session { "id" : UUID("510e6541-4d95-4dc8-9a9d-544dc83d9962") }
MongoDB server version: 5.0.9
================
Warning: the "mongo" shell has been superseded by "mongosh",
which delivers improved usability and compatibility.The "mongo" shell has been deprecated and will be removed in
an upcoming release.
For installation instructions, see
https://docs.mongodb.com/mongodb-shell/install/
================
Welcome to the MongoDB shell.
For interactive help, type "help".
For more comprehensive documentation, see
https://docs.mongodb.com/
Questions? Try the MongoDB Developer Community Forums
https://community.mongodb.com
> 1
1
> 2
2
> 2+2
4
>
> ^C
bye
>db
runoob
> show dbs
> db.runoob.insert({"name":" Novice tutorial "})
WriteCommandError({
"ok" : 0,
"errmsg" : "not authorized on runoob to execute command { insert: \"runoob\", ordered: true, lsid: { id: UUID(\"c42dc6b3-954f-44c0-8cef-60833165b085\") }, $db: \"runoob\" }",
"code" : 13,
"codeName" : "Unauthorized"
})
> db.createUser({ user:'admin',pwd:'123456',roles:[ { role:'userAdminAnyDatabase', db: 'admin'},"readWriteAnyDatabase"]});
Successfully added user: {
"user" : "admin",
"roles" : [
{
"role" : "userAdminAnyDatabase",
"db" : "admin"
},
"readWriteAnyDatabase"
]
}
> db.auth('admin', '123456')
1
> 1+1
2
> use runoob
switched to db runoob
> db
runoob
> show dbs
admin 0.000GB
config 0.000GB
local 0.000GB
> db.runoob.insert({"name":" Novice tutorial "})
WriteResult({ "nInserted" : 1 })
> show dbs
admin 0.000GB
config 0.000GB
local 0.000GB
runoob 0.000GB
> use runoob
switched to db runoob
> db.dropDatabase()
{
"ok" : 0,
"errmsg" : "not authorized on runoob to execute command { dropDatabase: 1.0, writeConcern: { w: \"majority\", wtimeout: 600000.0 }, lsid: { id: UUID(\"90abeefe-aaf6-4911-b5d1-22111be2c169\") }, $db: \"runoob\" }",
"code" : 13,
"codeName" : "Unauthorized"
}
> show dbs
admin 0.000GB
config 0.000GB
local 0.000GB
runoob 0.000GB
> db.grantRolesToUser ( "root", [ { role: "__system", db: "admin" } ] )
uncaught exception: Error: Could not find user "root" for db "runoob" :
[email protected]/mongo/shell/utils.js:25:13
[email protected]/mongo/shell/db.js:1594:15
@(shell):1:1
> db.dropDatabase()
{
"ok" : 0,
"errmsg" : "not authorized on runoob to execute command { dropDatabase: 1.0, writeConcern: { w: \"majority\", wtimeout: 600000.0 }, lsid: { id: UUID(\"90abeefe-aaf6-4911-b5d1-22111be2c169\") }, $db: \"runoob\" }",
"code" : 13,
"codeName" : "Unauthorized"
}
> use admin
switched to db admin
> db.auth('root','123456')
Error: Authentication failed.
0
> db.auth('admin', '123456')
1
> show dbs
admin 0.000GB
config 0.000GB
local 0.000GB
runoob 0.000GB
> use runoob
switched to db runoob
> db.dropDatabase()
{
"ok" : 0,
"errmsg" : "not authorized on runoob to execute command { dropDatabase: 1.0, writeConcern: { w: \"majority\", wtimeout: 600000.0 }, lsid: { id: UUID(\"90abeefe-aaf6-4911-b5d1-22111be2c169\") }, $db: \"runoob\" }",
"code" : 13,
"codeName" : "Unauthorized"
}
> use admin
switched to db admin
> db.createUser( {
... user: "sa",
... pwd: "sa",
... roles: [ { role: "root", db: "admin" } ]
... });
Successfully added user: {
"user" : "sa",
"roles" : [
{
"role" : "root",
"db" : "admin"
}
]
}
> db.auth('sa','sa');
1
> db.book.insert({"name":"cjn","age":24,"sex":" male "});
uncaught exception: SyntaxError: illegal character :
@(shell):1:49
> use runoob
switched to db runoob
> db
runoob
> show dbs
admin 0.000GB
config 0.000GB
local 0.000GB
runoob 0.000GB
> use runoob
switched to db runoob
> db.dropDatabase()
{ "ok" : 1 }
> show dbs
admin 0.000GB
config 0.000GB
local 0.000GB
> use runoob
switched to db runoob
> show dbs
admin 0.000GB
config 0.000GB
local 0.000GB
> db.runoob.insert({"name":" Novice tutorial "})
WriteResult({ "nInserted" : 1 })
> show dbs
admin 0.000GB
config 0.000GB
local 0.000GB
runoob 0.000GB
> use runoob
switched to db runoob
> db.dropDatabase()
{ "ok" : 1 }
> show dbs
admin 0.000GB
config 0.000GB
local 0.000GB
> use runoob
switched to db runoob
> db.createCollection("runoob")
{ "ok" : 1 }
> show tables
runoob
> db.runoob.drop()
true
> show tables
>
边栏推荐
- Data Lake (19): SQL API reads Kafka data and writes it to iceberg table in real time
- MLP-多层感知机
- 会话技术相关
- Matlab Fractional Order PID control
- What is the experience of writing concurrent tool classes (semaphore, cyclicbarrier, countdownlatch) by yourself in line 30?
- RSA of go language parses jsencrypt with secret key JS the encrypted ciphertext of this library failed
- 。 When calling, the incoming t refers to the Devi pass, which basically asks T2,
- Solution to the problem of "out of sight, out of mind, out of order" in the training competition
- 21st day of written test mandatory training
- SLAAC stateless address automatic configuration
猜你喜欢

Matlab sound signal processing frequency diagram signal filtering and playing sound

6-14 vulnerability exploitation rpcbind vulnerability exploitation

Worthington purified enzyme preparation helps neonatal cardiomyocyte isolation system

21st day of written test mandatory training

C語言經典練習題(2)——“冒泡排序(Bubble Sort)“
![[JS reverse hundred examples] a public resource trading network, reverse analysis of announcement URL parameters](/img/0b/3645a0a8ec677f96427b35bd371e7e.png)
[JS reverse hundred examples] a public resource trading network, reverse analysis of announcement URL parameters

SLAAC stateless address automatic configuration

Anchor point and anchor frame of target detection

MPLS VPN cross domain -optionb

Two stroke engine mean value model simulation
随机推荐
PAT甲级 1040 Longest Symmetric String
Android开发——Kotlin语法之Lambda表达式
Emqx v4.4.5 Publishing: new exclusive subscriptions and mqtt 5.0 publishing attribute support
Arduino interrupt realizes rising edge detection and executes other functions
An in-depth explanation of CAS is necessary for interview practice
Therefore, the command can be transmitted to the system and confirmed by the user. For master
Prosci Lag3 antibody: improve in vitro research and help cancer immunotherapy
Summary of Zhang Yu's 30 lectures on Advanced Mathematics
Tetris, 1
4.合宙Air32F103_LCD
Data Lake (19): SQL API reads Kafka data and writes it to iceberg table in real time
STL set容器
Qt ROS相关操作(运行终端指令、发布订阅自定义消息话题或服务、订阅图像并显示)
DOM相关的方法概念
Mitsubishi Ethernet module Yuanchuang intelligent control yc8000-fx connection MCGS operation method
Sqlserver backup restore
Extend the connection boundary, expand the business scope, and comprehensively move towards the era of Intelligent Cloud network 2.0
Technical dry goods | evaluation index based on mindspire detailed perflexity language model
Database foundation and installation
Worthington's test of hepatocyte separation system and related optimization schemes