{"id":14529207,"url":"https://github.com/bridge-codes/bridge-mongo","last_synced_at":"2025-08-18T19:04:25.214Z","repository":{"id":142356533,"uuid":"598262832","full_name":"bridge-codes/bridge-mongo","owner":"bridge-codes","description":"A fully typed mongoose ORM","archived":false,"fork":false,"pushed_at":"2023-03-13T13:43:11.000Z","size":6712,"stargazers_count":75,"open_issues_count":1,"forks_count":2,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-05-07T12:45:01.691Z","etag":null,"topics":["mongodb","mongoose","nodejs","typescript"],"latest_commit_sha":null,"homepage":"https://mongo.bridge.codes","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/bridge-codes.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2023-02-06T18:39:53.000Z","updated_at":"2025-05-04T01:58:57.000Z","dependencies_parsed_at":null,"dependency_job_id":"d4d87b35-ca8a-4a87-837f-1aac4c22ada8","html_url":"https://github.com/bridge-codes/bridge-mongo","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/bridge-codes/bridge-mongo","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bridge-codes%2Fbridge-mongo","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bridge-codes%2Fbridge-mongo/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bridge-codes%2Fbridge-mongo/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bridge-codes%2Fbridge-mongo/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/bridge-codes","download_url":"https://codeload.github.com/bridge-codes/bridge-mongo/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bridge-codes%2Fbridge-mongo/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":271043504,"owners_count":24689767,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-08-18T02:00:08.743Z","response_time":89,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["mongodb","mongoose","nodejs","typescript"],"created_at":"2024-09-05T00:00:57.499Z","updated_at":"2025-08-18T19:04:25.133Z","avatar_url":"https://github.com/bridge-codes.png","language":"TypeScript","readme":"\u003cdiv align=\"center\"\u003e\n  \u003ca href=\"https://bridge.codes\"\u003e\n      \u003cimg src=\"https://mongo.bridge.codes/img/bridge-mongo.svg\" height=\"80\" /\u003e\n  \u003c/a\u003e\n\u003c/div\u003e\n  \n\u003cdiv align=\"center\"\u003e\n\n \u003ca href=\"https://twitter.com/bridge_codes\"\u003e\n    \u003cimg alt=\"Twitter\" src=\"https://img.shields.io/twitter/url.svg?label=%40bridge_codes\u0026style=social\u0026url=https%3A%2F%2Ftwitter.com%2Falexdotjs\" /\u003e\n  \u003c/a\u003e\n  \u003ca href=\"https://discord.gg/yxjrwm7Bfr\"\u003e \n    \u003cimg alt=\"Discord\" src=\"https://img.shields.io/discord/1050622016673288282?color=7389D8\u0026label\u0026logo=discord\u0026logoColor=ffffff\" /\u003e\n  \u003c/a\u003e\n  \u003ca href=\"https://github.com/trpc/trpc/blob/main/LICENSE\"\u003e\n    \u003cimg alt=\"MIT License\" src=\"https://img.shields.io/github/license/trpc/trpc\" /\u003e\n  \u003c/a\u003e\n\u003c/div\u003e\n\n# Bridge Mongo\n\nBridge-mongo is a typed framework built on top of Mongoose, the popular MongoDB object-document mapping (ODM) library. It provides a type-safe approach to querying MongoDB databases that makes it almost impossible to write poorly constructed queries, all while using the same syntax as Mongoose.\n\n[Try it live](https://stackblitz.com/edit/bridge-mongo?file=index.ts\u0026view=editor)\n\n**👉 See more informations on [mongo.bridge.codes](https://mongo.bridge.codes) 👈**\n\n## Documentation\n\nFull documentation for `bridge-mongo` can be found [here](https://mongo.bridge.codes).\n\n## Installation\n\n```bash\n# npm\nnpm install bridge-mongo\n# Yarn\nyarn add bridge-mongo\n# pnpm\npnpm add bridge-mongo\n```\n\n## Quickstart\n\n### Define your Schemas\n\nDefining your schemas in bridge-mongo is just as easy as it is with Mongoose. You can define your schemas using Mongoose's schema syntax, and then use the createDB function to create your models.\n\nWhen you use `createDB`, bridge-mongo will automatically create and register each model with Mongoose using the keys from your schema object as the model names. This means you can define all of your schemas in one place and have them automatically created and registered as models for you.\n\n```ts twoslash title='index.ts'\nimport { createDB, Schema, mongoose } from 'bridge-mongo';\n\n// Defining a User Schema\nconst userSchema = new Schema({\n  name: { type: String, required: true },\n  email: String,\n  age: { type: Number, default: 18 },\n  job: { type: String, enum: ['developer', 'designer'] },\n  settings: {\n    isActive: Boolean,\n  },\n});\n\n// Defining a Post Schema\nconst postSchema = new Schema(\n  {\n    text: { type: String, required: true },\n    userId: { type: mongoose.Types.ObjectId, req: true },\n    likes: Number,\n  },\n  { timestamps: true },\n);\n\n// The keys correspond to the model Name\nconst DB = createDB({\n  User: userSchema,\n  Post: postSchema,\n});\n```\n\n### Connect to MongoDB\n\nConnecting to your MongoDB database using bridge-mongo is just as easy as it is with Mongoose. In fact, you can import `mongoose` directly from bridge-mongo and use its connect function to connect to your database.\n\n```ts twoslash title='index.ts'\nimport { mongoose } from 'bridge-mongo';\n\nconst launch = async () =\u003e {\n    await mongoose.connect('Your MongoDB URL here');\n\n    console.log('Connected!')\n}\n\nlaunch();\n```\n\n\n### Start enjoying type safety\n\nYou can enjoy the benefits of **total type safety** and guidance through TypeScript. The fully typed query results and error handling provided by bridge-mongo make it easy to write correct, efficient queries with confidence.\n\n Read the documentation to get started or get a look to the examples below.\n\n**Some Queries examples:**\n\n```ts\nimport { isError } from 'bridge-mongo';\n\nasync () =\u003e {\n  const user = await DB.user.create({ name: 'Nab' });\n\n  const post = await DB.post.findOne({ userId: user._id }, {text: 1});\n\n  if (!isError(post)) console.log(post)\n\n\n  const posts = await DB.post.find({ likes: { $gt: 10 }});\n\n  const res = await DB.user.findByIdAndUpdate(user._id, { name: 'Neo' }, { projection: { name: 1 } })\n}\n```\n\n**Some Aggregate examples:**\n\n```ts twoslash title='index.ts'\nasync () =\u003e {\n  \n  // Fetching all users that have created post with their posts\n  const blogers = await DB.user\n    .aggregate()\n    .project({ name: 1 })\n    .lookup({ from: 'posts', localField: '_id', foreignField: 'userId' })\n    .match({ 'posts.0': { $exists: true } })\n    .exec();\n\n  // Fetching all posts from the last 24 hours with their author only if he's \u003e= 21 years old\n\n  const yesterday = new Date(new Date().getTime() - 24 * 60 * 60 * 1000);\n\n  const posts = await DB.post\n    .aggregate()\n    .project({ text: 1, createdAt: 1, userId: 1 })\n    .match({ createdAt: { $gt: yesterday } })\n    .lookup({ from: 'users', let: { userId: '$userId' }, as: 'user' }, (user, { userId }) =\u003e\n      user\n        .match({ $expr: { $eq: ['$_id', userId] }, age: { $gte: 21 } })\n        .project({ name: 1 })\n        .limit(1),\n    )\n    .unwind('$user')\n    .unset('userId')\n    .exec();\n}\n```\n\n\nBridge-mongo is constantly evolving and adding new features to provide a fully typed, robust, and easy-to-use interface for interacting with MongoDB. While many essential functions are already implemented, there are still many more features that can be added to meet specific use cases. If you are interested in contributing or discussing features that you'd like to see implemented, you can join the [Bridge-mongo Discord server](https://discord.com/invite/yxjrwm7Bfr) and be a part of the community.\n","funding_links":[],"categories":["**1. Libraries**"],"sub_categories":["Database"],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbridge-codes%2Fbridge-mongo","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbridge-codes%2Fbridge-mongo","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbridge-codes%2Fbridge-mongo/lists"}