Mongodb
Posted on March 2, 2022
Tags: sql
1 Run mongodb as pod
2 Use mongosh to access remote mongodb
2.1 Install mongosh
create the file below
[mongodb-org-6.0]
name=MongoDB Repository
baseurl=https://repo.mongodb.org/yum/redhat/$releasever/mongodb-org/6.0/x86_64/
gpgcheck=1
enabled=1 gpgkey=https://www.mongodb.org/static/pgp/server-6.0.asc
sudo dnf clean all
sudo dnf install mongodb-mongosh
2.2 Using mongosh
mongosh 192.168.1.244:8098 --username root
3 Mongodb commands
3.1 Show databases
show dbs
# admin 100.00 KiB
# config 72.00 KiB
# local 72.00 KiB
3.2 Connect to database
use db_name
use admin
#switched to db admin
3.3 Show tables/collections
show tables
#system.users
#system.version
3.3.1 Create table/collection
db.createCollection("collection_name")
# { ok: 1 }
3.4 Get content in table/collection
show db.table_name.find()
show db["table_name"].find()
show db.system.users.find()
show db["system.users"].find()
# [
# {
# _id: 'admin.root',
# userId: new UUID("f79b0c3d-31a9-4e46-9269-277bdde4efdf"),
# user: 'root',
# db: 'admin',
# credentials: {
# 'SCRAM-SHA-1': {
# iterationCount: 10000,
# salt: 'i0xsSUoJXIAYtmbpG1RjZQ==',
# storedKey: 'jAXQ8hXM45aak0IO2B+YgBLwzUY=',
# serverKey: 'MmpwyWd3q7Ir203bcfuQyDPRNJU='
# },
# 'SCRAM-SHA-256': {
# iterationCount: 15000,
# salt: 'dxAAZf2cn+EXBJwV2Aa0Ubb2I1vfXVZ3JrDDSg==',
# storedKey: 'pEJCZtKWeb6tZfOsOScYQ6Mh2DYFZjfG4R7nPBh8/ws=',
# serverKey: 'BJMN76NJw08FMxd4u+6KQV9VmAR3wiv6H6h0eyiKIlg='
# }
# },
# roles: [ { role: 'root', db: 'admin' } ]
# }
# ]