diff --git a/Docker/MongoDB_Docker/README.md b/Docker/MongoDB_Docker/README.md new file mode 100644 index 0000000..4f00f3a --- /dev/null +++ b/Docker/MongoDB_Docker/README.md @@ -0,0 +1,90 @@ +# Running MongoDB in Docker + + + +This guide outlines the steps to run MongoDB in a Docker container with an attached volume. This allows you to persist the data outside the container and preserve it even when the container is removed. + +## Prerequisites + +- Docker installed on your machine + +## Step 1: + +1. Replace `` and `` with the desired container name and volume name. + +2. Run MongoDB in a Docker container with the volume attached: + + ``` + docker run -d --name -p 27017:27017 -v :/data/db mongo:latest + ``` + + This command starts a MongoDB container named ``, maps port `27017` of the container to port `27017` on the host machine, and attaches the volume called `` to the container's `/data/db` directory. + +## Step 2: + +### 1. Open [Studio3T](https://studio3t.com/) app to access the mongodb + +### 2. Connect to the mongodb using the following URI: + +``` +mongodb://localhost:27017 +``` + +### 3. Add a name for the database. + +### 4. Create a new database. + + + + + +### 5. To select the database: + +``` +use my_db +``` + +This command switches to the `my_db` database. If the database doesn't exist, MongoDB will create it automatically when you start using it. + +### 6. Create a Collection in the selected database + +``` +db.createCollection("my_collection") +``` + +This command creates a collection named `my_collection` within the `my_db` database. + + + +### 7. Insert documents into the collection: + +``` +db.mycollection.insertOne({ +"name": "John Doe", +"age": 30, +"email": "johndoe@example.com", +"address": { + "street": "123 Main St", + "city": "New York", + "state": "NY", + "zipcode": "10001" +}, +"interests": ["programming", "reading", "traveling"] +}) +``` + +This command inserts multiple documents into the `my_collection` collection with corresponding `name`, `age`, `email`, `address`, `interests` values. + +### 8. Find documents in the collection: + +``` +db.my_collection.find() +``` + +This command retrieves all documents from the `my_collection` collection and displays them. + +### 9. Delete the created collection: + +``` +db.mycollection.drop() +``` diff --git a/Docker/MongoDB_Docker/add_database.png b/Docker/MongoDB_Docker/add_database.png new file mode 100644 index 0000000..597d876 Binary files /dev/null and b/Docker/MongoDB_Docker/add_database.png differ diff --git a/Docker/MongoDB_Docker/add_database_name.png b/Docker/MongoDB_Docker/add_database_name.png new file mode 100644 index 0000000..9981244 Binary files /dev/null and b/Docker/MongoDB_Docker/add_database_name.png differ diff --git a/Docker/MongoDB_Docker/create_collection.png b/Docker/MongoDB_Docker/create_collection.png new file mode 100644 index 0000000..f136681 Binary files /dev/null and b/Docker/MongoDB_Docker/create_collection.png differ diff --git a/Docker/MongoDB_Docker/docker.png b/Docker/MongoDB_Docker/docker.png new file mode 100755 index 0000000..0210740 Binary files /dev/null and b/Docker/MongoDB_Docker/docker.png differ diff --git a/Docker/MongoDB_Docker/mongo.png b/Docker/MongoDB_Docker/mongo.png new file mode 100755 index 0000000..df96860 Binary files /dev/null and b/Docker/MongoDB_Docker/mongo.png differ diff --git a/Docker/MongoDB_Docker/open_shell.png b/Docker/MongoDB_Docker/open_shell.png new file mode 100644 index 0000000..cf8f884 Binary files /dev/null and b/Docker/MongoDB_Docker/open_shell.png differ