Skip to content

Commit

Permalink
access MongoDB Atlas from mongo shell
Browse files Browse the repository at this point in the history
  • Loading branch information
NielMc committed Apr 3, 2023
1 parent 805eee5 commit 815c7a0
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 25 deletions.
21 changes: 10 additions & 11 deletions .devcontainer/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
FROM ubuntu:22.04
FROM ubuntu:20.04

ENV PYTHON_VERSION 3.8.12
ENV PYTHON_VERSION 3.8.11
ENV DEBIAN_FRONTEND=noninteractive
#Set of all dependencies needed for pyenv to work on Ubuntu
RUN apt-get update \
&& apt-get install -y --no-install-recommends make build-essential libssl-dev libpq-dev zlib1g-dev libbz2-dev libreadline-dev libsqlite3-dev wget ca-certificates curl llvm libncurses5-dev xz-utils tk-dev libxml2-dev libxmlsec1-dev libffi-dev liblzma-dev mecab-ipadic-utf8 git postgresql-client telnet
#Install pyenv and mongo shell dependencies
RUN apt-get update && apt-get install -y gnupg2
RUN apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv 20691eec35216c63caf66ce1656408e390cfb1f5 \
&& sh -c 'echo "deb http://repo.mongodb.org/apt/ubuntu focal/mongodb-org/4.4 multiverse" | tee /etc/apt/sources.list.d/mongodb-org-4.4.list' \
&& apt-get update -y \
&& apt-get install -y make build-essential libssl-dev zlib1g-dev libbz2-dev libreadline-dev libsqlite3-dev wget ca-certificates curl llvm libncurses5-dev xz-utils tk-dev libxml2-dev libxmlsec1-dev libffi-dev liblzma-dev mecab-ipadic-utf8 git mongodb-org-shell links

RUN curl https://cli-assets.heroku.com/install.sh | sh
RUN curl -fsSL https://deb.nodesource.com/setup_16.x | bash - && apt-get install -y nodejs

ARG USERNAME=codeany
RUN useradd -ms /bin/bash $USERNAME
Expand All @@ -28,12 +30,9 @@ RUN set -ex \
&& python3 -m pip install --no-cache-dir --upgrade pip \
&& python3 -m pip install --no-cache-dir --upgrade setuptools wheel virtualenv pipenv pylint rope flake8 mypy autopep8 pep8 pylama pydocstyle bandit notebook twine

ENV PATH=$PATH:"/home/codeany/.local/bin"

RUN echo 'alias python=python3' >> ~/.bashrc && \
echo 'export PIP_USER=yes' >> ~/.bashrc && \
echo 'alias pip=pip3' >> ~/.bashrc && \
echo 'alias psql="psql mydb"' >> ~/.bashrc
echo 'alias pip=pip3' >> ~/.bashrc

COPY ./build-assets/heroku_config.sh /home/$USERNAME/.theia/heroku_config.sh
RUN echo 'alias heroku_config=". $HOME/.theia/heroku_config.sh"' >> ~/.bashrc
Expand All @@ -44,4 +43,4 @@ RUN echo 'alias make_url="python3 $HOME/.theia/make_url.py "' >> ~/.bashrc
USER root
RUN chown -R $USERNAME:$USERNAME /home/$USERNAME/.theia

CMD ["tail", "-f", "/dev/null"]
CMD ["tail", "-f", "/dev/null"]
4 changes: 2 additions & 2 deletions .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
"ms-python.python",
"formulahendry.auto-close-tag",
"eventyret.bootstrap-4-cdn-snippet",
"hookyqr.beautify",
"esbenp.prettier-vscode",
"matt-rudge.auto-open-preview-panel",
"ms-toolsai.jupyter",
"ms-toolsai.jupyter-keymap",
Expand All @@ -31,7 +31,7 @@
"**/core.mongo*": true,
"**/core.python*": true
},
"editor.defaultFormatter": "HookyQR.beautify",
"editor.defaultFormatter": "esbenp.prettier-vscode",
"python.linting.pycodestyleEnabled": true,
"python.terminal.activateEnvironment": false,
"workbench.iconTheme": "none"
Expand Down
15 changes: 5 additions & 10 deletions .devcontainer/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,10 @@ services:
build:
context: .
dockerfile: Dockerfile
volumes:
- "/tmp/postgres/socket:/var/run/postgresql"

psql:
image: postgres:11.9
mongo:
image: mongo:latest
environment:
- POSTGRES_PASSWORD=pass1234
- POSTGRES_USER=codeany
- POSTGRES_DB=mydb
network_mode: service:app
volumes:
- "/tmp/postgres/socket:/var/run/postgresql"
MONGO_INITDB_ROOT_USERNAME: codeany
MONGO_INITDB_ROOT_PASSWORD: pass1234
network_mode: service:app
25 changes: 23 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,33 @@

Welcome,

This is the Code Institute student template for Codeanywhere. We have preinstalled all of the tools you need to get started. It's perfectly ok to use this template as the basis for your project submissions.
This is the Code Institute student template for the mongo lessons. We have preinstalled all of the tools you need to get started. It's perfectly ok to use this template as the basis for your project submissions.

You can safely delete this README.md file, or change it for your own project. Please do read it at least once, though! It contains some important information about Codeanywhere and the extensions we use. Some of this information has been updated since the video content was created. The last update to this file was: **March 3rd, 2023**
You can safely delete this README.md file, or change it for your own project. Please do read it at least once, though! It contains some important information about Codeanywhere and the extensions we use. Some of this information has been updated since the video content was created. The last update to this file was: **April 3rd, 2023**

## Codeanywhere Reminders

# IDE

- **Connect to Mongo CLI on a IDE**
- navigate to your MongoDB Clusters Sandbox
- click **"Connect"** button
- select **"Connect with the MongoDB shell"**
- select **"I have the mongo shell installed"**
- choose option 4.4 for : **"Select your mongo shell version"**
- choose option: **"Run your connection string in your command line"**
- `mongo "mongodb+srv://<CLUSTER-NAME>.mongodb.net/<DBname>" --username <USERNAME>`
- replace all `<angle-bracket>` keys with your own data
- enter password *(will not echo **\*\*\*\*** *on screen)\*

#### Clear screen in Mongo Shell:

- `cls`

#### Show all database collections:

- `show collections`

To run a frontend (HTML, CSS, Javascript only) application in Codeanywhere, in the terminal, type:

`python3 -m http.server`
Expand Down

0 comments on commit 815c7a0

Please sign in to comment.