Add Mongoose + DocumentDB playground#415
Conversation
There was a problem hiding this comment.
Pull request overview
Adds a new self-contained Node.js playground under documentdb-playground/mongoose/ to demonstrate and validate using Mongoose (ODM) against the DocumentDB gateway (TLS + direct connection), including both an Express REST API and a standalone CRUD/compatibility test script.
Changes:
- Introduces an Express + Mongoose demo API (
/health,/booksCRUD,/stats/genresaggregation). - Adds a standalone Mongoose CRUD/compatibility suite plus helper scripts to run locally via
kubectl port-forward(and optionally deploy in-cluster). - Provides Kubernetes manifests and detailed README covering setup, configuration, and known compatibility caveats.
Reviewed changes
Copilot reviewed 15 out of 16 changed files in this pull request and generated 6 comments.
Show a summary per file
| File | Description |
|---|---|
| documentdb-playground/mongoose/README.md | Documents architecture, setup paths, configuration, and compatibility notes. |
| documentdb-playground/mongoose/documentdb.yaml | Sample DocumentDB instance manifest sized/pinned for the playground. |
| documentdb-playground/mongoose/k8s/mongoose-app.yaml | Optional in-cluster Deployment/Service for the demo app. |
| documentdb-playground/mongoose/scripts/lib.sh | Shared helpers for resolving the connection string and managing port-forward. |
| documentdb-playground/mongoose/scripts/run-app.sh | Runs the Express app locally via a temporary port-forward. |
| documentdb-playground/mongoose/scripts/run-test.sh | Runs the CRUD/compatibility test locally via a temporary port-forward. |
| documentdb-playground/mongoose/scripts/deploy.sh | Optional path: build image, (kind) load, create Secret, deploy app in-cluster. |
| documentdb-playground/mongoose/scripts/cleanup.sh | Removes the optional in-cluster demo deployment. |
| documentdb-playground/mongoose/app/package.json | Declares Node app metadata and dependencies (express, mongoose). |
| documentdb-playground/mongoose/app/package-lock.json | Locks dependency graph for reproducible installs. |
| documentdb-playground/mongoose/app/db.js | Centralizes DocumentDB-specific Mongoose connection options + URI sanitization. |
| documentdb-playground/mongoose/app/models/book.js | Defines the sample Book schema/model and indexes. |
| documentdb-playground/mongoose/app/server.js | Implements the REST API and health endpoint. |
| documentdb-playground/mongoose/app/mongoose-crud-test.js | Standalone CRUD/compatibility test runner with pass/fail summary. |
| documentdb-playground/mongoose/app/Dockerfile | Container image build for the optional in-cluster deployment path. |
| documentdb-playground/mongoose/app/.dockerignore | Excludes local-only artifacts from Docker build context. |
Files not reviewed (1)
- documentdb-playground/mongoose/app/package-lock.json: Generated file
| gateway_port() { | ||
| local uri="$1" port | ||
| port=$(echo "$uri" | sed -E 's#.*@[^:/]+:([0-9]+).*#\1#') | ||
| echo "${port:-10260}" | ||
| } |
| local i | ||
| for i in $(seq 1 15); do | ||
| if grep -q "Forwarding from" "$logfile" 2>/dev/null; then | ||
| break | ||
| fi | ||
| if ! kill -0 "$pid" 2>/dev/null; then | ||
| echo "port-forward to $svc failed; see $logfile" >&2 | ||
| return 1 | ||
| fi | ||
| sleep 1 | ||
| done | ||
|
|
||
| echo "$pid" | ||
| } |
| // Fetch a single book by id. | ||
| app.get('/books/:id', async (req, res) => { | ||
| try { | ||
| const book = await Book.findById(req.params.id).lean(); | ||
| if (!book) return res.status(404).json({ error: 'not found' }); | ||
| res.json(book); | ||
| } catch (err) { | ||
| res.status(400).json({ error: err.message }); | ||
| } |
| echo "Installing app dependencies (express, mongoose)..." | ||
| (cd "$APP_DIR" && npm install --omit=dev --no-audit --no-fund >/dev/null) |
| echo "Installing test dependencies (mongoose)..." | ||
| (cd "$APP_DIR" && npm install --omit=dev --no-audit --no-fund >/dev/null) |
| # Install dependencies first for better layer caching. | ||
| COPY package.json ./ | ||
| RUN npm install --omit=dev |
Signed-off-by: Rayhan Hossain <hossain.rayhan@outlook.com>
79726a5 to
8521785
Compare
|
🤖 Auto-triaged by documentdb-triage-tool. Applied: Reasoningcomponent from path globs (playground, docs); effort from diff stats (2243+0 LOC, 16 files); LLM: Adds a new self-contained Mongoose + DocumentDB playground under documentdb-playground/, including app code, test suites, helper scripts, manifests, and documentation — a multi-file addition to one component. If a label is wrong, remove it manually and ping |
Add Mongoose + DocumentDB playground
Adds a self-contained playground under
documentdb-playground/mongoose/that demonstrates and validates using Mongoose (the popular Node.js MongoDB ODM) against DocumentDB.What's included
app/server.js,app/models/book.js,app/db.js) — health, CRUD, and a genre-aggregation endpoint.app/mongoose-crud-test.js) — connect, index sync, insertOne/insertMany, filtered find + sort + limit, countDocuments, updateOne, findOneAndUpdate, aggregation, unique-index enforcement, deleteOne, and drop.scripts/):run-app.sh/run-test.sh— primary path: run the app/tests locally against an in-cluster DocumentDB via a temporarykubectl port-forward.deploy.sh/cleanup.sh— optional path: build the image, load into kind, and run the app in-cluster.lib.sh— shared helpers (resolveMONGO_URIfrom the DocumentDB status, manage the port-forward).documentdb.yaml(sample DocumentDB instance sized for the demo) andk8s/mongoose-app.yaml(in-cluster Deployment + Service).How Mongoose connects
The DocumentDB gateway speaks the MongoDB wire protocol as a standalone server over TLS, so the app/test require
directConnection: true,tls: true,tlsAllowInvalidCertificates: true(for the default self-signed install), and stripreplicaSet=rs0from the connection string. The scripts handle this automatically.Validation (local kind, all default images