当前位置:网站首页>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
边栏推荐
- QT 项目 表格新建列名称设置 需求练习(找数组消失的数字、最大值)
- Kbone与小程序跨端开发的一些思考
- Restore backup data on GCS with br
- 二进制、八进制、十六进制
- 自适应非欧表征广告检索系统AMCAD
- Kotlin Android 环境搭建
- 手机号国际区号JSON格式另附PHP获取
- 1.19.11.SQL客户端、启动SQL客户端、执行SQL查询、环境配置文件、重启策略、自定义函数(User-defined Functions)、构造函数参数
- Confirm the future development route! Digital economy, digital transformation, data This meeting is very important
- 史上最全MongoDB之初识篇
猜你喜欢
随机推荐
【刷题记录】2. 两数相加
史上最全MongoDB之初识篇
机械臂速成小指南(十):可达工作空间
What is the experience of maintaining Wanxing open source vector database
One of oscp tools: dirsearch usage Encyclopedia
When QT uses qtooltip mouse to display text, the picture of the button will also be displayed and the prompt text style will be modified
三重半圆环进度条,直接拿去就能用
Storage of data
Triple half circle progress bar, you can use it directly
map和set的实现
Simple implementation of AVL tree insertion and verification operations
golang 压缩和解压zip文件
What is Ba? How about Ba? What is the relationship between Ba and Bi?
Food Chem|深度学习根据成分声明准确预测食品类别和营养成分
Some thoughts on cross end development of kbone and applet
使用 BR 恢复 GCS 上的备份数据
二叉搜索树的实现
[development software] tilipa Developer Software
Class constant pool and runtime constant pool
UltraEdit-32 温馨提示:右协会,取消 bak文件[通俗易懂]