Skip to content

Repository files navigation

Intro-DB

In this repo we will work with:

  • Postgresql to showcase relational DBMS
  • MongoDB

The main purpose is to see the difference in terms of flexibility. Of course over Internet you will find much more explanation but don't hesitate to reach out if you have any question.

Some ressources:

  1. Data source: https://www.nyc.gov/site/tlc/about/tlc-trip-record-data.page
  2. Work with MongoDB: https://github.com/sonyarianto/docker-compose-mongodb/blob/master/README.md
  3. https://www.baeldung.com/linux/mongodb-as-docker-container

How to use different docker-compose files

You can specify a docker compose file in the docker-compose up command using the following command:

docker-compose -f docker-compose-file.yml up

Where docker-compose-file.yml is the name of your docker compose file.

Source: (1) docker compose up | Docker Documentation. https://docs.docker.com/engine/reference/commandline/compose_up/. (2) docker compose | Docker Documentation. https://docs.docker.com/engine/reference/commandline/compose/. (3) Use Docker Compose | Docker Documentation. https://docs.docker.com/get-started/08_using_compose/.

How to use MongoDB

It is possible to use the mongo shell to interact with the MongoDB database. To do so, follow these steps:

  1. Ensure that you have the MongoDB shell installed on your local machine. You can download it from the official MongoDB website: https://www.mongodb.com/try/download/shell.

  2. Start the Docker Compose setup by running the following command in the terminal:

docker-compose up -d

# connect to pgcli (postgresql)
docker exec -it intro-db_postgres_1 psql -U username ny_taxi

To connect to a PostgreSQL database using pgcli, you can use the following command-line options:

  1. Basic Connection:

    • If you know the host address, port, username, and database name, you can use the following format:
      pgcli -h <host> -p <port> -U <username> <dbname>
      
      • Replace <host>, <port>, <username>, and <dbname> with your actual values.
  2. Using a URL:

    • You can also connect directly using a URL:
      pgcli 'postgresql://user:password@localhost:port/db_name'
      
      • Replace user, password, localhost, port, and db_name with your specific details.
  3. Examples:

    • Connect to a local database named local_database:
      pgcli local_database
      
    • Connect to a remote database using a URL:
      pgcli postgres://amjith:passw0rd@example.com:5432/app_db
      
    • Specify host and port explicitly:
      pgcli -h localhost -p 5432 -U amjith app_db
      

Remember to adjust the parameters according to your PostgreSQL setup. Happy querying! 🐘

  1. Open a new terminal window and run the following command to enter the MongoDB container:
docker exec -it <container_id> mongo -u admin -p password --authenticationDatabase admin

Replace <container_id> with the actual container ID of the MongoDB container. You can find the container ID by running docker ps command.

  1. You should now be in the MongoDB shell, connected to your database. You can execute various commands to interact with the database. For example, you can switch to a specific database, list collections, and perform queries.

Here's an example of using the mongo shell commands:

# Switch to the desired database
use sampledb

# Insert a document into the collection
db.samplecollection.insert({name: "Alice", age: 27})

# Query the collection
db.samplecollection.find()

You can enter additional MongoDB shell commands as needed to interact with the database. The mongo shell provides a powerful interface for managing and querying MongoDB databases.

Remember to replace sampledb and samplecollection with your actual database name and collection name.

If you prefer a more interactive experience, you can also use MongoDB GUI clients like MongoDB Compass or Robo3T to connect to the MongoDB container and perform database operations.

About

A weak introduction to data base introduction

Resources

Stars

0 stars

Watchers

1 watching

Forks

Releases

Packages

Used by

Contributors

Languages