Skip to content

Add Mongoose + Document DB Playground#1

Merged
hossain-rayhan merged 2 commits into
documentdb:mainfrom
hossain-rayhan:rayhan/mongoose-playground
Jul 24, 2026
Merged

Add Mongoose + Document DB Playground#1
hossain-rayhan merged 2 commits into
documentdb:mainfrom
hossain-rayhan:rayhan/mongoose-playground

Conversation

@hossain-rayhan

Copy link
Copy Markdown
Collaborator

Add Mongoose + DocumentDB playground

First playground for documentdb-playground: a quick, hands-on guide for testing DocumentDB with Mongoose, the most popular MongoDB ODM for Node.js. Everything runs locally against a DocumentDB container in Docker — no Kubernetes, no cloud, no image builds.

What's included

  • Express + Mongoose REST API (playgrounds/mongoose/app/) — /books CRUD, /health, and a /stats/genres aggregation endpoint.
  • Standalone CRUD/compatibility test suite (app/mongoose-crud-test.js) — exercises connect, schema/index creation, insert, query, update, aggregation, unique-index enforcement, and delete, printing a pass/fail summary.
  • Local-only helper scripts (scripts/):
    • run-test.sh — start DocumentDB (if needed) and run the compatibility suite end-to-end (agent/CI-friendly).
    • run-app.sh — start DocumentDB (if needed) and serve the demo API on :3000.
    • start-documentdb.sh / stop-documentdb.sh — manage the local documentdb-local container.
    • lib.sh — shared container lifecycle, readiness wait, and connection-string builder.
  • Docs — playground README (setup, config reference, compatibility notes, troubleshooting) and an updated root README that indexes playgrounds and leaves room for future ones (PyMongo, Beanie, k8s/cloud, etc.).

How DocumentDB runs locally

Uses the official image, bound to loopback:

docker run -dt -p 127.0.0.1:10260:10260 --name documentdb-local \
  ghcr.io/documentdb/documentdb/documentdb-local:latest \
  --username docdbadmin --password '<password>'

Notes / design decisions

  • Port is bound to 127.0.0.1 — keeps the DB off external interfaces and works around a Docker Desktop/WSL2 quirk where the IPv4 loopback mapping was otherwise unreachable.
  • Default username is docdbadmin (the gateway rejects the reserved name documentdb).
  • Mongoose connects with directConnection: true, tls: true, tlsAllowInvalidCertificates: true, and strips replicaSet=rs0 automatically.
  • run-app.sh and run-test.sh are independent and can run concurrently (app uses DB mongoose_demo, tests use mongoose_test) — no port-forward to clobber.

Testing

Verified end-to-end against documentdb-local:latest:

  • Test suite: Passed: 13, Failed: 0, Known issues: 0 (the older findById _id "pruned relation" bug is resolved in the current image).
  • API smoke test: /health, POST/GET /books, and /stats/genres all working.
  • Confirmed the app and test suite run simultaneously without interference.

@hossain-rayhan
hossain-rayhan requested a review from Copilot July 23, 2026 21:36

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Copilot wasn't able to review this pull request because it exceeds the maximum number of files (300). Try reducing the number of changed files and requesting a review from Copilot again.

@hossain-rayhan
hossain-rayhan force-pushed the rayhan/mongoose-playground branch from 3b07f39 to ec28e3e Compare July 23, 2026 21:40
Comment thread playgrounds/mongoose/README.md Outdated
| Unique indexes | ✅ Supported | Duplicate keys raise the standard `E11000` error. |
| Aggregation pipelines | ✅ Common stages | `$match`, `$group`, `$unwind`, `$sort`, etc. Atlas-only stages differ.|
| `findById` / `_id` lookups | ✅ Supported | Works on the current `documentdb-local:latest` image. |
| `$vectorSearch` | ❌ Not supported | Atlas-only operator; not implemented by DocumentDB. |

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Current DocumentDB implements native $vectorSearch

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Thanks. Added new tests for vecotrSearch and updated README.

@patty-chow patty-chow left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

left one comment on the readme, otherwise LGTM

Signed-off-by: Rayhan Hossain <hossain.rayhan@outlook.com>
@hossain-rayhan
hossain-rayhan merged commit 6131aa2 into documentdb:main Jul 24, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants