quarta-feira, 20 de fevereiro de 2019

Debian 9 and MongoDB

Debian 9 and MongoDB


This week I upgraded my Mint running under Debian 9.3 (LMDE 3).  

See:

lucio@lucio:~$ cat /etc/debian_version 
9.3


So, I installed Mongo using the default repository. My current version of python 3 is 3.5.3, and I do not want to update python because I'm afraid to break my project - maybe I have to upgrade the pip packages if I did.


Ok... I tried updating python and using it with Mongo 4.0, but the numpy didn't work...and maybe many others too. So, I gave up.


Installing Mongo

lucio@lucio:~$ sudo apt install mongodb



So, this are the versions of my installations.

lucio@lucio:~/desenv/project$ python3 -V
Python 3.5.3

lucio@lucio:~$ mongod --version
db version v3.2.11
git version: 009580ad490190ba33d1c6253ebd8d91808923e4
OpenSSL version: OpenSSL 1.0.2q  20 Nov 2018
allocator: tcmalloc
modules: none
build environment:
    distarch: x86_64
    target_arch: x86_64


It worked fine!

Restoring backups

It's easy restoring backups in Mongo, just use mongorestore - mongorestore <backup path>.

lucio@lucio:~$ mongorestore desenv/project/dump/20190207/



--- 

Installing Mongo 4.0


I will record here the step by step to install Mongo 4.0 in Debian 9.

Make sure you have the curl installed. If not, install it.

lucio@lucio:~$ sudo apt install curl

Install the key of mongodb repository.

lucio@lucio:~$ curl https://www.mongodb.org/static/pgp/server-4.0.asc | sudo apt-key add -

Create the file mongodb-org-4.0.list:

lucio@lucio:~$ sudo vim /etc/apt/sources.list.d/mongodb-org-4.0.list

This will open a new blank file. Paste in the following:

deb http://repo.mongodb.org/apt/debian stretch/mongodb-org/4.0 main

Save and close the file, then update your package cache:

lucio@lucio:~$ sudo apt update

Install the mongodb-org package to install the server and some supporting tools:

lucio@lucio:~$ sudo apt install mongodb-org

Finally, enable and start the mongod service to get your MongoDB database running:

lucio@lucio:~$ sudo systemctl enable mongod
lucio@lucio:~$ sudo systemctl start mongod

Check if Mongo is running:

lucio@lucio:~$ sudo systemctl status mongod

That's all!!!



segunda-feira, 18 de fevereiro de 2019

Creating and updating root password in Mysql


# Creating the first root password

If you have just installed mysql-server and have not set the root password, you will create the password like this:

$ sudo mysqladmin -uroot password 'password' 


# Updating the root password

For updating the root password, you can do like this:

$ sudo mysqladmin -u root -p'oldpassword' password 'newpassword'




sexta-feira, 14 de dezembro de 2018

Regex on VS Code

Place underscore between words

Find: ([A-Za-z])( )([A-Za-z])
Replace: $1_$3

Find

Ano
Sit reg
Dcih
Apres
Espec
Cgc hosp
Org rec
Ident
Org loc
Nome pac
Logr
Numero
Compl
Tipo bairr
Cs
Cs cod

Replace 

Ano
Sit_reg
Dcih
Apres
Espec
Cgc_hosp
Org_rec
Ident
Org_loc
Nome_pac
Logr
Numero
Compl
Tipo_bairr
Cs
Cs_cod








quinta-feira, 22 de novembro de 2018

Importing files from pg_dump


For importing files generated by pg_dump command, use the command pg_restore, like that:

$ pg_restore -Uusername -hlocalhost -c -v -Fc -ddatabase < file.pg_dump

Options:
  • -U: username
  • -h: host
  • -c: drop database before recreating
  • -v: verbose mode
  • -Fc: the archive is in the custom format of pg_dump
  • -d: database

For more options look on page manpage by pg_restore.

$ man pg_restore


SQL files

In case you have a sql file to import, use this command:

$ psql -Uusername -hlocalhost -v -ddatabase < file.sql


That's all!

quarta-feira, 31 de outubro de 2018

VS Code - Switch between edit and terminal

  1. Open Keyboard Shortcuts [Ctrl + K, Ctrl + S]
  2. Search for Focus Terminal
enter image description here
  1. Set your shortcut, in my case I used Ctrl+'
Check the editor shortcut searching for Focus First Editor, default Ctrl + 1
enter image description here