Skip to content

Commit 1325aa8

Browse files
authored
destination/mongodb: adjust based on new auth approach (#609)
* adjust based on new auth approach * add comments for temporary code * add working defaults for the mongodb deployment * add some documentation
1 parent 03311e6 commit 1325aa8

File tree

6 files changed

+70
-12
lines changed

6 files changed

+70
-12
lines changed

docker/mongodb/README.md

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,21 @@
22

33
This sample demonstrates how to deploy and use MongoDB in your pipeline. Please note: this image is provided by MongoDB and is offered as-is, with no specific support from Quix.
44

5+
## Using with a Quix Cloud MongoDB Connector
6+
7+
This deployment will work seamlessly with the [Quix Cloud MongoDB sink connector](https://github.com/quixio/quix-samples/tree/main/python/destinations/mongodb).
8+
9+
Simply provide the following arguments to the connector,
10+
where `username` and `password` are the credentials used when
11+
creating this service:
12+
13+
```shell
14+
MONGODB_USERNAME="<YOUR USERNAME>" # (default: "admin")
15+
MONGODB_PASSWORD="<YOUR PASSWORD>"
16+
MONGODB_HOST="mongodb"
17+
MONGODB_PORT="27017"
18+
```
19+
520
## How to Run
621

722
1. Log in or sign up at [Quix](https://portal.platform.quix.io/signup?xlink=github) and navigate to the Code Samples section.

python/destinations/mongodb/README.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,20 @@
44
demonstrates how to consume data from a Kafka topic in Quix and write the data to a
55
MongoDB database using the [Quix Streams MongoDB sink](https://quix.io/docs/quix-streams/connectors/sinks/mongodb-sink.html).
66

7+
## Using with a Quix Cloud MongoDB Service
8+
9+
This deployment will work seamlessly with a [Quix Cloud MongoDB service](https://github.com/quixio/quix-samples/tree/main/docker/mongodb).
10+
11+
Simply provide the following arguments to this connector,
12+
where `username` and `password` are are the credentials used when
13+
creating the **Quix Cloud MongoDB service**:
14+
15+
```shell
16+
MONGODB_USERNAME="<YOUR USERNAME>" # (default: "admin")
17+
MONGODB_PASSWORD="<YOUR PASSWORD>"
18+
MONGODB_HOST="mongodb"
19+
MONGODB_PORT="27017"
20+
```
721
## How to run
822

923
Create a [Quix](https://portal.platform.quix.io/signup?xlink=github) account or log-in and visit the `Connectors` tab to use this connector.

python/destinations/mongodb/dockerfile

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,12 @@
11
FROM python:3.12.5-slim-bookworm
2-
2+
3+
# TODO: remove this RUN block when done doing "@ git+" install in requirements.txt
4+
# This should be done BEFORE merging PR
5+
RUN apt-get update && \
6+
apt-get install -y git && \
7+
apt-get clean && \
8+
rm -rf /var/lib/apt/lists/*
9+
310
# Set environment variables for non-interactive setup and unbuffered output
411
ENV DEBIAN_FRONTEND=noninteractive \
512
PYTHONUNBUFFERED=1 \
@@ -12,11 +19,6 @@ ARG MAINAPPPATH=.
1219
# Set working directory inside the container
1320
WORKDIR /app
1421

15-
RUN apt-get update && \
16-
apt-get install -y git && \
17-
apt-get clean && \
18-
rm -rf /var/lib/apt/lists/*
19-
2022
# Copy requirements to leverage Docker cache
2123
COPY "${MAINAPPPATH}/requirements.txt" "${MAINAPPPATH}/requirements.txt"
2224

python/destinations/mongodb/library.json

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,26 @@
2222
"Required": true
2323
},
2424
{
25-
"Name": "MONGODB_URL",
25+
"Name": "MONGODB_HOST",
26+
"Type": "EnvironmentVariable",
27+
"InputType": "FreeText",
28+
"Description": "MongoDB host name",
29+
"DefaultValue": "mongodb",
30+
"Required": true
31+
},
32+
{
33+
"Name": "MONGODB_USERNAME",
34+
"Type": "EnvironmentVariable",
35+
"InputType": "FreeText",
36+
"Description": "MongoDB username",
37+
"DefaultValue": "admin",
38+
"Required": true
39+
},
40+
{
41+
"Name": "MONGODB_PASSWORD",
2642
"Type": "EnvironmentVariable",
2743
"InputType": "Secret",
28-
"Description": "MongoDB url; most commonly mongodb://username:password@host:port",
44+
"Description": "MongoDB password",
2945
"Required": true
3046
},
3147
{
@@ -42,6 +58,14 @@
4258
"Description": "MongoDB collection name",
4359
"Required": true
4460
},
61+
{
62+
"Name": "MONGODB_PORT",
63+
"Type": "EnvironmentVariable",
64+
"InputType": "FreeText",
65+
"Description": "MongoDB host port",
66+
"DefaultValue": "27017",
67+
"Required": false
68+
},
4569
{
4670
"Name": "MONGODB_DOCUMENT_MATCHER",
4771
"Type": "EnvironmentVariable",

python/destinations/mongodb/main.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,10 +100,13 @@ def document_matcher_env_parser() -> Optional[Callable[[SinkItem], MongoQueryFil
100100
kwargs_defaults = get_kwargs_defaults()
101101
mongodb_sink = MongoDBSink(
102102
# required settings
103-
url=os.environ["MONGODB_URL"],
103+
host=os.environ["MONGODB_HOST"],
104+
username=os.environ["MONGODB_USERNAME"],
105+
password=os.environ["MONGODB_PASSWORD"],
104106
db=os.environ["MONGODB_DB"],
105107
collection=os.environ["MONGODB_COLLECTION"],
106108
# optional settings (have defaults)
109+
port=int(port) if (port := os.getenv("MONGODB_PORT")) else kwargs_defaults["port"],
107110
update_method=os.getenv("MONGODB_UPDATE_METHOD", kwargs_defaults["update_method"]),
108111
upsert=_as_bool(os.getenv("MONGODB_UPSERT", kwargs_defaults["upsert"])),
109112
document_matcher=document_matcher_env_parser() or kwargs_defaults["document_matcher"],
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
quixstreams[mongodb] @ git+https://github.com/quixio/quix-streams.git@sink/mongodb-add-metadata-fix
2-
python-dotenv
3-
1+
# TODO: remove "@ git+" version of install before merging PR
2+
quixstreams[mongodb] @ git+https://github.com/quixio/quix-streams.git@sink/mongodb-auth-adjust
3+
python-dotenv

0 commit comments

Comments
 (0)