-
Notifications
You must be signed in to change notification settings - Fork 591
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge remote-tracking branch 'origin/main' into jinser/connector-ssl
- Loading branch information
Showing
355 changed files
with
6,204 additions
and
2,850 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
# Use an official Python runtime as a parent image | ||
FROM python:3.8-slim | ||
|
||
# Set the working directory to /app | ||
WORKDIR /app | ||
|
||
# Copy the requirements file into the container at /app | ||
COPY ./mongodb/requirements.txt /app | ||
COPY ./mongodb/app.py /app | ||
|
||
# Install any needed packages specified in requirements.txt | ||
RUN pip install -r requirements.txt | ||
|
||
# Make port 5000 available to the world outside this container | ||
EXPOSE 5000 | ||
|
||
# Define environment variables | ||
ENV MONGO_HOST mongodb | ||
ENV MONGO_PORT 27017 | ||
ENV MONGO_DB_NAME random_data | ||
|
||
# Run app.py when the container launches | ||
CMD ["python", "app.py"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
import os | ||
import pymongo | ||
from faker import Faker | ||
|
||
# To check the data through mongosh or mongo, run the following command: | ||
# > mongosh mongodb://admin:[email protected]:27017 | ||
# > rs0 [direct: primary] test> use random_data | ||
# > rs0 [direct: primary] random_data> db.users.find() | ||
# > rs0 [direct: primary] random_data> db.users.count() | ||
|
||
# Connect to MongoDB | ||
mongo_host = os.environ["MONGO_HOST"] | ||
mongo_port = os.environ["MONGO_PORT"] | ||
mongo_db_name = os.environ["MONGO_DB_NAME"] | ||
|
||
url = f"mongodb://{mongo_host}:{mongo_port}" | ||
client = pymongo.MongoClient(url) | ||
db = client[mongo_db_name] | ||
|
||
# Generate random data | ||
fake = Faker() | ||
collection = db["users"] | ||
|
||
for _ in range(55): | ||
user_data = { | ||
"name": fake.name(), | ||
"address": fake.address(), | ||
"email": fake.email(), | ||
} | ||
collection.insert_one(user_data) | ||
|
||
# Count the number of records in the collection | ||
total_records = collection.count_documents({}) | ||
|
||
# Close the MongoDB connection | ||
client.close() | ||
print(f"Random data generated and inserted into MongoDB: {url}") | ||
|
||
# Print insertion summary | ||
print("Insertion summary:") | ||
print(f"Total records in the collection: {total_records}") |
File renamed without changes.
File renamed without changes.
Oops, something went wrong.