Skip to content

Add Mongoose + DocumentDB playground#415

Open
hossain-rayhan wants to merge 1 commit into
documentdb:mainfrom
hossain-rayhan:rayhan/mongoose-playground
Open

Add Mongoose + DocumentDB playground#415
hossain-rayhan wants to merge 1 commit into
documentdb:mainfrom
hossain-rayhan:rayhan/mongoose-playground

Conversation

@hossain-rayhan

Copy link
Copy Markdown
Collaborator

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

  • Express + Mongoose REST API (app/server.js, app/models/book.js, app/db.js) — health, CRUD, and a genre-aggregation endpoint.
  • Standalone Mongoose CRUD/compatibility suite (app/mongoose-crud-test.js) — connect, index sync, insertOne/insertMany, filtered find + sort + limit, countDocuments, updateOne, findOneAndUpdate, aggregation, unique-index enforcement, deleteOne, and drop.
  • Helper scripts (scripts/):
    • run-app.sh / run-test.shprimary path: run the app/tests locally against an in-cluster DocumentDB via a temporary kubectl port-forward.
    • deploy.sh / cleanup.shoptional path: build the image, load into kind, and run the app in-cluster.
    • lib.sh — shared helpers (resolve MONGO_URI from the DocumentDB status, manage the port-forward).
  • Manifestsdocumentdb.yaml (sample DocumentDB instance sized for the demo) and k8s/mongoose-app.yaml (in-cluster Deployment + Service).
  • README with architecture, connection requirements, a Mongoose↔DocumentDB compatibility matrix, and troubleshooting.

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 strip replicaSet=rs0 from the connection string. The scripts handle this automatically.

Validation (local kind, all default images

Copilot AI review requested due to automatic review settings July 1, 2026 20:43

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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, /books CRUD, /stats/genres aggregation).
  • 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

Comment on lines +44 to +48
gateway_port() {
local uri="$1" port
port=$(echo "$uri" | sed -E 's#.*@[^:/]+:([0-9]+).*#\1#')
echo "${port:-10260}"
}
Comment on lines +68 to +81
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"
}
Comment on lines +44 to +52
// 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 });
}
Comment on lines +36 to +37
echo "Installing app dependencies (express, mongoose)..."
(cd "$APP_DIR" && npm install --omit=dev --no-audit --no-fund >/dev/null)
Comment on lines +34 to +35
echo "Installing test dependencies (mongoose)..."
(cd "$APP_DIR" && npm install --omit=dev --no-audit --no-fund >/dev/null)
Comment on lines +6 to +8
# Install dependencies first for better layer caching.
COPY package.json ./
RUN npm install --omit=dev
Signed-off-by: Rayhan Hossain <hossain.rayhan@outlook.com>
@hossain-rayhan hossain-rayhan force-pushed the rayhan/mongoose-playground branch from 79726a5 to 8521785 Compare July 1, 2026 20:50
@documentdb-triage-tool documentdb-triage-tool Bot added documentation Improvements or additions to documentation ecosystem enhancement New feature or request labels Jul 1, 2026
@documentdb-triage-tool

Copy link
Copy Markdown

🤖 Auto-triaged by documentdb-triage-tool.

Applied: ecosystem, documentation, enhancement
Project fields suggested: Component playground · Priority P2 · Effort XL · Status Needs Review
Confidence: 0.95 (mixed)

Reasoning

component 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 @patty-chow so the rules can be tuned. The bot will not re-label items that already have component labels.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

documentation Improvements or additions to documentation ecosystem enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants