Skip to content

Latest commit

 

History

History
160 lines (128 loc) · 3.12 KB

mongodb.md

File metadata and controls

160 lines (128 loc) · 3.12 KB

MONGODB cheatsheet

check running processes

ps -edaf | grep mongosh

#or #sudo lsof -i | grep mongosh

#or #sudo lsof -iTCP -sTCP:LISTEN -n -P | grep mongosh

kill previous instances

sudo kill 12054

make sure to use conda mongodb

$: which mongod

 /home/uname/miniconda3/envs/kubas/bin/mongod

$: mongod --version

> db version v6.0.2
> Build Info: {
>     "version": "6.0.2",
>     "gitVersion": "94fb7dfc8b974f1f5343e7ea394d0d9deedba50e",
>     "openSSLVersion": "OpenSSL 3.1.3 19 Sep 2023",
>     "modules": [],
>     "allocator": "tcmalloc",
>     "environment": {
>         "distarch": "x86_64",
>         "target_arch": "x86_64"
>     }
> }

make sure mongodb folder exists and is empty

rm -r /home/mdi0316/.mongodb/jfremote
mkdir /home/mdi0316/.mongodb/jfremote
mkdir /home/mdi0316/.mongodb/jfremote/db
mkdir /home/mdi0316/.mongodb/jfremote/log

ON WORKSTATION

Re-launch DB after shut down

mongod --dbpath /home/mdi0316/.mongodb/kubas/db/ --logpath /home/mdi0316/.mongodb/kubas/log/kubas.log --fork --bind_ip_all --auth

Starting and configuring the database

  1. Set in /etc/mongod.conf
>> # Where to store the data.
>> storage:
>> dbPath=/home/uname/mongodb
>>
>> #where to log
>> systemLog:
>>   path=/home/uname/mongodb/mongodb.log
>>
>> net:
>>   bind_ip = 127.0.0.1,10.100.192.47
>>   port = 27017
>>
>> security:
>>   authorization: enabled
user = "mdi0316"
pwd = "dhxe-3736-%+=!-WHHF"
port = 27017
dbpath = /home/mdi0316/.mongodb/kubas/db
dblog = /home/mdi0316/.mongodb/kubas/log/mnh.log
  1. Starting mongod without any admin/password:
mongod --port $port --dbpath $dbpath
  1. Connect to the database:
mongosh --port $port
  1. Setup admin user and password in the mongosh shell:
use admin
db.createUser({
    user:"mdi0316",
    pwd:"psw1",
    roles:[ {role:"root", db:"admin"},
            {role:"dbOwner", db:"admin"}]
    })
db.grantRolesToUser(
    "mdi0316",
    [  { role: "dbOwner", db: "kubas" } ,
       { role: "dbOwner", db: "pgel" } ]
    )
  1. create kubas db and initiate with something
use exemple
my_dict = { "name": "Marco", "age": "36" }
db.ex_collection.insertOne(my_dict)
db.ex_collection.findOne()

>> {
>>    "_id" : ObjectId("64919e6aa09061a14012da20"),
>>     "name" : "Marco",
>>     "age" : "36"
>> }
  1. stop db in 1) and 2)

  2. Starting mongod as a daemon (fork)

mongod --port $port --dbpath $dbpath --logpath $logpath --fork --bind_ip_all --auth
  1. Now, admin can connect using:
mongosh --port 27018 -u "mdi0316" -p "GEJR-shfb-6252-*():" --authenticationDatabase "admin"

ON CLUSTER

8.0) Connect from another server (AT cluster) - default port

$ mongosh --port 27018 -u "uname" -p 'pswd' --authenticationDatabase "admin" --host 10.100.192.47

8.1) if not on opened port - activate tunnel on terminal 1

$ ssh -N -L 27018:localhost:27018 uname@10.100.192.47
  1. for slurm submissions - open the tunnel nodeXYZ -> masternode. Outside of the network 10.100.192.1 could not work
$ ssh -N -L 27018:localhost:27018 uname@bezavrdat-master01