{"id":13485102,"url":"https://github.com/denodrivers/mongo","last_synced_at":"2025-05-15T02:09:21.961Z","repository":{"id":37098559,"uuid":"190690177","full_name":"denodrivers/mongo","owner":"denodrivers","description":"🍃 MongoDB driver for Deno 🦕","archived":false,"fork":false,"pushed_at":"2025-03-14T07:07:36.000Z","size":634,"stargazers_count":516,"open_issues_count":46,"forks_count":92,"subscribers_count":14,"default_branch":"main","last_synced_at":"2025-05-01T19:06:04.061Z","etag":null,"topics":["database","deno","deno-deploy","driver","mongodb","typescript"],"latest_commit_sha":null,"homepage":"https://deno.land/x/mongo","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/denodrivers.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":".github/FUNDING.yml","license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":".github/CODEOWNERS","security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null},"funding":{"github":["lucsoft"]}},"created_at":"2019-06-07T04:57:09.000Z","updated_at":"2025-04-25T07:47:30.000Z","dependencies_parsed_at":"2024-01-05T21:00:00.873Z","dependency_job_id":"a505e091-4991-4359-8613-219ca98ec67a","html_url":"https://github.com/denodrivers/mongo","commit_stats":{"total_commits":324,"total_committers":53,"mean_commits":6.113207547169812,"dds":0.6358024691358024,"last_synced_commit":"a49057db8583cd29003c686e0ad8178914126199"},"previous_names":["denodrivers/deno_mongo","manyuanrong/deno_mongo"],"tags_count":49,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/denodrivers%2Fmongo","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/denodrivers%2Fmongo/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/denodrivers%2Fmongo/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/denodrivers%2Fmongo/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/denodrivers","download_url":"https://codeload.github.com/denodrivers/mongo/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":253685217,"owners_count":21947306,"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","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":["database","deno","deno-deploy","driver","mongodb","typescript"],"created_at":"2024-07-31T17:01:46.050Z","updated_at":"2025-05-15T02:09:21.901Z","avatar_url":"https://github.com/denodrivers.png","language":"TypeScript","funding_links":["https://github.com/sponsors/lucsoft"],"categories":["TypeScript","Libraries","Modules"],"sub_categories":["JavaScript","Database"],"readme":"# deno_mongo\n\n\u003e **deno_mongo** is a **MongoDB** database driver developed for Deno. supports\n\u003e Deno Deploy as well.\n\n\u003cdiv align=\"center\"\u003e\n  \u003cimg src=\"https://user-images.githubusercontent.com/47688578/168461127-aeadaaf5-224d-4664-8a1d-4789c4ee9281.jpg\" width=\"210\"\u003e\n\u003c/div\u003e\n\n## ATTENTION\n\n**Deno have added the support for npm modules. so you can also use `npm:mongodb`\ndriver from now.**\\\nEach of these two drivers has its own advantages and disadvantages. you can\nfollow [this](https://github.com/denodrivers/mongo/issues/380) issue for more\ndetails. In short:\n\n- if you want to use basic MongoDB operations and you don't care about\n  stability, this driver just works.\n- if you want most of MongoDB feature working with Deno and you don't care about\n  the possible overheads by using node compat layer, you may try the\n  `npm:mongodb` driver\n- if you are using MongoDB Atlas, using\n  [atlas_sdk](https://github.com/erfanium/atlas_sdk) can be your best option.\n\n[![tag](https://img.shields.io/github/tag/manyuanrong/deno_mongo.svg)](https://github.com/manyuanrong/deno_mongo/releases)\n[![Build Status](https://github.com/manyuanrong/deno_mongo/workflows/ci/badge.svg?branch=main)](https://github.com/manyuanrong/deno_mongo/actions)\n[![license](https://img.shields.io/github/license/manyuanrong/deno_mongo.svg)](https://github.com/manyuanrong/deno_mongo)\n[![Discord server](https://img.shields.io/discord/768918486575480863?color=blue\u0026label=Ask%20for%20help%20here\u0026logo=discord\u0026style=flat-square)](https://discord.gg/HEdTCvZUSf)\n\n## Links\n\n- [Docs](https://doc.deno.land/https/deno.land/x/mongo/mod.ts)\n\n### Import\n\nReplace `LATEST_VERSION` with\n[current latest version](https://deno.land/x/mongo)\n\n```ts\nimport {\n  Bson,\n  MongoClient,\n} from \"https://deno.land/x/mongo@LATEST_VERSION/mod.ts\";\n```\n\n### Connect\n\n```ts\nconst client = new MongoClient();\n\n// Connecting to a Local Database\nawait client.connect(\"mongodb://127.0.0.1:27017\");\n\n// Connecting to a Mongo Atlas Database\nawait client.connect({\n  db: \"\u003cdb_name\u003e\",\n  tls: true,\n  servers: [\n    {\n      host: \"\u003cdb_cluster_url\u003e\",\n      port: 27017,\n    },\n  ],\n  credential: {\n    username: \"\u003cusername\u003e\",\n    password: \"\u003cpassword\u003e\",\n    db: \"\u003cdb_name\u003e\",\n    mechanism: \"SCRAM-SHA-1\",\n  },\n});\n\n// Connect using srv url\nawait client.connect(\n  \"mongodb+srv://\u003cusername\u003e:\u003cpassword\u003e@\u003cdb_cluster_url\u003e/\u003cdb_name\u003e?authMechanism=SCRAM-SHA-1\",\n);\n```\n\n### Access Collection\n\n```ts\n// Defining schema interface\ninterface UserSchema {\n  _id: ObjectId;\n  username: string;\n  password: string;\n}\n\nconst db = client.database(\"test\");\nconst users = db.collection\u003cUserSchema\u003e(\"users\");\n```\n\n### Insert\n\n```ts\nconst insertId = await users.insertOne({\n  username: \"user1\",\n  password: \"pass1\",\n});\n\nconst insertIds = await users.insertMany([\n  {\n    username: \"user1\",\n    password: \"pass1\",\n  },\n  {\n    username: \"user2\",\n    password: \"pass2\",\n  },\n]);\n```\n\n### Find\n\n```ts\nconst user1 = await users.findOne({ _id: insertId });\n\nconst all_users = await users.find({ username: { $ne: null } }).toArray();\n\n// find by ObjectId\nconst user1_id = await users.findOne({\n  _id: new ObjectId(\"SOME OBJECTID STRING\"),\n});\n```\n\n### Count\n\n```ts\nconst count = await users.countDocuments({ username: { $ne: null } });\n\nconst estimatedCount = await users.estimatedDocumentCount({\n  username: { $ne: null },\n});\n```\n\n### Aggregation\n\n```ts\nconst docs = await users.aggregate([\n  { $match: { username: \"many\" } },\n  { $group: { _id: \"$username\", total: { $sum: 1 } } },\n]).toArray();\n```\n\n### Update\n\n```ts\nconst { matchedCount, modifiedCount, upsertedId } = await users.updateOne(\n  { username: { $ne: null } },\n  { $set: { username: \"USERNAME\" } },\n);\n\nconst { matchedCount, modifiedCount, upsertedId } = await users.updateMany(\n  { username: { $ne: null } },\n  { $set: { username: \"USERNAME\" } },\n);\n```\n\n### Replace\n\n```ts\nconst { matchedCount, modifiedCount, upsertedId } = await users.replaceOne(\n  { username: \"a\" },\n  {\n    username: \"user1\",\n    password: \"pass1\",\n  }, // new document\n);\n```\n\n### Delete\n\n```ts\nconst deleteCount = await users.deleteOne({ _id: insertId });\n\nconst deleteCount2 = await users.deleteMany({ username: \"test\" });\n```\n\n### Cursor methods\n\n```ts\nconst cursor = users.find();\n\n// Skip \u0026 Limit\ncursor.skip(10).limit(10);\n\n// iterate results\nfor await (const user of cursor) {\n  console.log(user);\n}\n\n// or save results to array (uses more memory)\nconst users = await cursor.toArray();\n```\n\n### GridFS\n\n```ts\n// Upload\nconst bucket = new GridFSBucket(db);\nconst upstream = bucket.openUploadStream(\"test.txt\");\n\nconst writer = upstream.getWriter();\nwriter.write(fileContents);\n\nawait writer.close();\n\n// Download\nconst file = await new Response(bucket.openDownloadStream(id)).text();\n```\n\n## Community Resources\n\n### Tools\n\n- [atlas_sdk](https://github.com/erfanium/atlas_sdk) TypeSafe MongoDB Atlas Data\n  API SDK for Deno \u0026 Deno Deploy\n- [dangoDB](https://github.com/oslabs-beta/dangoDB) A MongoDB ODM for Deno\n- [denomongo-unittest-utils](https://github.com/Gang-of-Fork/denomongo-unittest-utils)\n  mock mongo-collections for use in unit-tests\n\n### Examples\n\n- [deno-deploy-mongo](https://github.com/erfanium/deno-deploy-mongo) A simple\n  app with Deno, MongoDB and oak deployed on Deno Deploy and MongoDB Atlas\n- [deno_rest](https://github.com/vicky-gonsalves/deno_rest) A simple oak based\n  boilerplate for RESTful apis using deno_mongo\n\n## Contributing\n\n### Local testing with Docker\n\n1. `docker run -d  -p 27017:27017 mongo`\n2. deno test -A\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdenodrivers%2Fmongo","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdenodrivers%2Fmongo","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdenodrivers%2Fmongo/lists"}