当前位置:网站首页>Mongo shell, the most complete mongodb in history
Mongo shell, the most complete mongodb in history
2022-07-07 04:05:00 【janyxe】
MongoDB List of articles
- In the history of the most complete MongoDB First knowledge of
- In the history of the most complete MongoDB Deployment of
- In the history of the most complete MongoDB And Mongo Shell Use
If this article is helpful to your development path , Please give me a compliment , Your support is my motivation to stick to blogging
Scan the QR code at the bottom of the article to get the e-book and the latest interview materials
Preface
This series of courses will take you in the form of face-to-face test questions Go deep into distributed topics MongoDB. This article takes you in depth MongoDB Shell Use
Mongo Shell Introduce
- MongoDB Bring their own Javascript Shell, Can be found in Shell Use the command line and MongoDB Real column interaction
- Mongo Shell from Mozilla Official JavaScript Kernel interpreter , For internal use SpiderMonkey
- SpiderMonkey Yes ECMA Script Standard compatibility is very good , Support ES 6(ECMA Script 6)
Mongo Shell start-up
Mongo Shell The parameters are as follows
[[email protected] mongodb]# mongo --help
MongoDB shell version v4.4.14
usage: mongo [options] [db address] [file names (ending in .js)]
db address can be:
foo foo database on local machine
192.168.0.5/foo foo database on 192.168.0.5 machine
192.168.0.5:9999/foo foo database on 192.168.0.5 machine on port 9999
mongodb://192.168.0.5:9999/foo connection string URI can also be used
Options:
--ipv6 enable IPv6 support (disabled by
default)
--host arg server to connect to
--port arg port to connect to
-h [ --help ] show this usage information
--version show version information
--verbose increase verbosity
--shell run the shell after executing files
--nodb don't connect to mongod on startup - no 'db address' arg expected --norc will not run the ".mongorc.js" file on start up --quiet be less chatty --eval arg evaluate javascript --disableJavaScriptJIT disable the Javascript Just In Time compiler --enableJavaScriptJIT enable the Javascript Just In Time compiler --disableJavaScriptProtection allow automatic JavaScript function marshalling --retryWrites automatically retry write operations upon transient network errors --disableImplicitSessions do not automatically create and use implicit sessions --jsHeapLimitMB arg set the js scope's heap size limit
--idleSessionTimeout arg (=0) Terminate the Shell session if it's been
idle for this many seconds
FLE AWS Options:
--awsAccessKeyId arg AWS Access Key for FLE Amazon KMS
--awsSecretAccessKey arg AWS Secret Key for FLE Amazon KMS
--awsSessionToken arg Optional AWS Session Token ID
--keyVaultNamespace arg database.collection to store encrypted
FLE parameters
--kmsURL arg Test parameter to override the URL for
KMS
AWS IAM Options:
--awsIamSessionToken arg AWS Session Token for temporary
credentials
TLS Options:
--tls use TLS for all connections
--tlsCertificateKeyFile arg PEM certificate/key file for TLS
--tlsCertificateKeyFilePassword arg Password for key in PEM file for TLS
--tlsCAFile arg Certificate Authority file for TLS
--tlsCRLFile arg Certificate Revocation List file for TLS
--tlsAllowInvalidHostnames Allow connections to servers with
non-matching hostnames
--tlsAllowInvalidCertificates Allow connections to servers with
invalid certificates
--tlsFIPSMode Activate FIPS 140-2 mode at startup
--tlsDisabledProtocols arg Comma separated list of TLS protocols to
disable [TLS1_0,TLS1_1,TLS1_2]
Authentication Options:
-u [ --username ] arg username for authentication
-p [ --password ] arg password for authentication
--authenticationDatabase arg user source (defaults to dbname)
--authenticationMechanism arg authentication mechanism
--gssapiServiceName arg (=mongodb) Service name to use when authenticating
using GSSAPI/Kerberos
--gssapiHostName arg Remote host name to use for purpose of
GSSAPI/Kerberos authentication
file names: a list of files to run. files have to end in .js and will exit after unless --shell is specified
[[email protected] mongodb]#
The optional parameters are as follows
mongo -u <user> -p <pass> --host <host> --port <port>
Parameters | explain |
---|---|
–port | Port number , Not specified as default port 27017 |
-u / -username | user name |
-p / -password | password |
-authenticationDatabase | Authentication database |
Local clients can directly mongo start-up
[[email protected] mongodb]# mongo
Mongo Shell Common commands
Database common commands
show dbs / show databases command
Concept
Show database list
Command application
> show dbs;
admin 0.000GB
config 0.000GB
local 0.000GB
use Database name command
Concept
Switch database , When the database does not exist, it will be created automatically
Command application
> show dbs;
admin 0.000GB
config 0.000GB
local 0.000GB
db.dropDatabase() command
Concept
Delete the collection
Command application
> db.emp.drop()
true
> show collections
Collection common operations
show collections / show tables View set commands
Concept
Query the collection list data of the current database
Command application
> show dbs
admin 0.000GB
config 0.000GB
local 0.000GB
> use test
switched to db test
> db.emp.insert({
i:1})
WriteResult({
"nInserted" : 1 })
> show collections
emp
db.collections( Collection name ).stats() View set details command
Concept
View collection details
Command application
> db.emp.stats()
{
"ns" : "test.emp",
"size" : 33,
"count" : 1,
"avgObjSize" : 33,
"storageSize" : 20480,
"freeStorageSize" : 0,
"capped" : false,
"wiredTiger" : {
"metadata" : {
"formatVersion" : 1
},
...
"scaleFactor" : 1,
"ok" : 1
}
db.collections( Collection name ).drop() Delete the collection command
Concept
Delete the collection
Command application
> db.emp.drop()
true
> show collections
User role commands
show roles View the role list command
Concept
View role list
Command application
> show roles
{
"role" : "dbAdmin",
"db" : "test",
"isBuiltin" : true,
"roles" : [ ],
"inheritedRoles" : [ ]
}
{
"role" : "dbOwner",
"db" : "test",
"isBuiltin" : true,
"roles" : [ ],
"inheritedRoles" : [ ]
}
{
"role" : "enableSharding",
"db" : "test",
"isBuiltin" : true,
"roles" : [ ],
"inheritedRoles" : [ ]
}
{
"role" : "read",
"db" : "test",
"isBuiltin" : true,
"roles" : [ ],
"inheritedRoles" : [ ]
}
{
"role" : "readWrite",
"db" : "test",
"isBuiltin" : true,
"roles" : [ ],
"inheritedRoles" : [ ]
}
{
"role" : "userAdmin",
"db" : "test",
"isBuiltin" : true,
"roles" : [ ],
"inheritedRoles" : [ ]
}
db.createUser( User information ) Create user command
Concept
Create user
Command format
db.createUser({user:“ user name ”,pwd:“ name ”,roles:[“ role ”]})
Command parameter | meaning |
---|---|
user | User name |
pwd | password |
roles | Character list |
Command application
establish test library , And designate test The administrator of the library
> use test
switched to db test
> dn.createUser({
user:"test",pwd:"test",roles:['dbOwner']})
uncaught exception: ReferenceError: dn is not defined :
@(shell):1:1
> use test
switched to db test
> db.createUser({
user:"test",pwd:"test",roles:['dbOwner']})
Successfully added user: {
"user" : "test", "roles" : [ "dbOwner" ] }
> show users
{
"_id" : "test.test",
"userId" : UUID("d9be5de9-8c28-4b2b-8d88-530be7846b14"),
"user" : "test",
"db" : "test",
"roles" : [
{
"role" : "dbOwner",
"db" : "test"
}
],
"mechanisms" : [
"SCRAM-SHA-1",
"SCRAM-SHA-256"
]
}
>
db.dropUser( User name ) Delete user command
Concept
Create user
Command format
db.dropUser(“ user name ”)
Command application
db.dropUser(“test”)
> use test
switched to db test
> dn.createUser({
user:"test",pwd:"test",roles:['dbOwner']})
uncaught exception: ReferenceError: dn is not defined :
@(shell):1:1
> use test
switched to db test
> db.createUser({
user:"test",pwd:"test",roles:['dbOwner']})
Successfully added user: {
"user" : "test", "roles" : [ "dbOwner" ] }
> show users
{
"_id" : "test.test",
"userId" : UUID("d9be5de9-8c28-4b2b-8d88-530be7846b14"),
"user" : "test",
"db" : "test",
"roles" : [
{
"role" : "dbOwner",
"db" : "test"
}
],
"mechanisms" : [
"SCRAM-SHA-1",
"SCRAM-SHA-256"
]
}
>
to see somebody for the first time , I don't know what to give you . Simply send hundreds of e-books and the latest interview materials , I wish you a better job , Scan the QR code below to get
边栏推荐
- 复杂因子计算优化案例:深度不平衡、买卖压力指标、波动率计算
- Mobile measurement and depth link platform - Branch
- 1.19.11.SQL客户端、启动SQL客户端、执行SQL查询、环境配置文件、重启策略、自定义函数(User-defined Functions)、构造函数参数
- 如何检测mysql代码运行是否出现死锁+binlog查看
- ABAP 動態內錶分組循環
- How to manage the expiration of enterprise distribution certificates- How to manage Enterprise Distribution certificate expiration?
- 如何编写一个程序猿另一个面试官眼前一亮的简历[通俗易懂]
- Index of MySQL
- 用头像模仿天狗食月
- Docker部署Mysql8的实现步骤
猜你喜欢
预处理——插值
Summer 2022 daily question 1 (1)
API data interface of A-share index component data
[MySQL] row sorting in MySQL
复杂因子计算优化案例:深度不平衡、买卖压力指标、波动率计算
On file uploading of network security
机械臂速成小指南(十):可达工作空间
Mobile measurement and depth link platform - Branch
Confirm the future development route! Digital economy, digital transformation, data This meeting is very important
1.19.11.SQL客户端、启动SQL客户端、执行SQL查询、环境配置文件、重启策略、自定义函数(User-defined Functions)、构造函数参数
随机推荐
Kotlin Android environment construction
Food Chem|深度学习根据成分声明准确预测食品类别和营养成分
Implementation steps of docker deploying mysql8
Binary, octal, hexadecimal
Native MySQL
QT 项目 表格新建列名称设置 需求练习(找数组消失的数字、最大值)
Que savez - vous de la sérialisation et de l'anti - séquence?
Some common software related
Class常量池与运行时常量池
map和set的实现
Introduction to opensea platform developed by NFT trading platform (I)
【编码字体系列】OpenDyslexic字体
2022中青杯C题城市交通思路分析
如何编写一个程序猿另一个面试官眼前一亮的简历[通俗易懂]
The most complete learning rate adjustment strategy in history LR_ scheduler
使用 TiDB Lightning 恢复 GCS 上的备份数据
机器人(自动化)课程的持续学习-2022-
termux设置电脑连接手机。(敲打命令贼快),手机termux端口8022
ABAP Dynamic Inner table Group cycle
QT item table new column name setting requirement exercise (find the number and maximum value of the array disappear)