{"id":15647813,"url":"https://github.com/erfanium/atlas_sdk","last_synced_at":"2025-04-30T11:15:42.688Z","repository":{"id":41449021,"uuid":"481914556","full_name":"erfanium/atlas_sdk","owner":"erfanium","description":"TypeSafe MongoDB Atlas Data API SDK for Deno, Deno Deploy and Node.js","archived":false,"fork":false,"pushed_at":"2024-04-25T09:43:24.000Z","size":35,"stargazers_count":43,"open_issues_count":4,"forks_count":6,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-04-19T01:31:52.721Z","etag":null,"topics":["atlas","deno","mongo-atlas","mongodb","sdk","typescript"],"latest_commit_sha":null,"homepage":"https://deno.land/x/atlas_sdk","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/erfanium.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","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":"2022-04-15T09:57:27.000Z","updated_at":"2025-02-05T21:02:33.000Z","dependencies_parsed_at":"2023-12-14T10:52:02.979Z","dependency_job_id":"7f770cb0-ef1c-470f-8ecd-5a1f86d7d3ea","html_url":"https://github.com/erfanium/atlas_sdk","commit_stats":{"total_commits":37,"total_committers":6,"mean_commits":6.166666666666667,"dds":0.5945945945945945,"last_synced_commit":"093609c6e8a59558b5756efcdc6b00aede9ebc85"},"previous_names":[],"tags_count":13,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/erfanium%2Fatlas_sdk","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/erfanium%2Fatlas_sdk/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/erfanium%2Fatlas_sdk/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/erfanium%2Fatlas_sdk/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/erfanium","download_url":"https://codeload.github.com/erfanium/atlas_sdk/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":251687686,"owners_count":21627614,"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":["atlas","deno","mongo-atlas","mongodb","sdk","typescript"],"created_at":"2024-10-03T12:21:15.581Z","updated_at":"2025-04-30T11:15:42.658Z","avatar_url":"https://github.com/erfanium.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Atlas SDK\n\n\u003e **atlas_sdk** is a TypeSafe\n\u003e [MongoDB Atlas Data API](https://www.mongodb.com/docs/atlas/api/data-api/#introduction)\n\u003e SDK for Deno \u0026 Deno Deploy \u0026 Web\n\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## Why\n\n- [x/mongo](https://github.com/denodrivers/deno_mongo) is not production ready\n  and reliable, but this module is\n- It's serverless friendly. because atlas data api uses `https` protocol,\n  there's no need to wait for MongoClient to be connected. this will reduce cold\n  start time.\n- Can be used on Web and Node.js v17+ environments, because this module only\n  depends on `fetch`\n\n## Links\n\n- [Docs](https://doc.deno.land/https/deno.land/x/atlas_sdk/mod.ts)\n\n## Permissions\n\nThis module needs `net` permission. use `deno run --allow-net` command\n\n### Import\n\nReplace `LATEST_VERSION` with\n[current latest version](https://deno.land/x/atlas_sdk)\n\n```ts\nimport {\n  MongoClient,\n  ObjectId,\n} from \"https://deno.land/x/atlas_sdk@LATEST_VERSION/mod.ts\";\n```\n\n### Constructor\n\n#### Authenticate via email and password\n\n[Documentation](https://www.mongodb.com/docs/atlas/app-services/authentication/email-password/#std-label-email-password-authentication)\n\n```ts\nconst client = new MongoClient({\n  endpoint: \"https://data.mongodb-api.com/app/YOUR_APP_ID/endpoint/data/v1\",\n  dataSource: \"YOUR_CLUSTER_NAME\", // e.g. \"Cluster0\"\n  auth: {\n    email: \"YOUR_EMAIL\",\n    password: \"YOUR_PASSWORD\",\n  },\n});\n```\n\n#### Authenticate via api-key\n\n[Documentation](https://www.mongodb.com/docs/atlas/app-services/authentication/api-key/#std-label-api-key-authentication)\n\n```ts\nconst client = new MongoClient({\n  endpoint: \"https://data.mongodb-api.com/app/YOUR_APP_ID/endpoint/data/v1\",\n  dataSource: \"YOUR_CLUSTER_NAME\", // e.g. \"Cluster0\"\n  auth: {\n    apiKey: \"YOUR_API_KEY\",\n  },\n});\n```\n\n#### Authenticate via custom JWT\n\n[Documentation](https://www.mongodb.com/docs/atlas/app-services/authentication/custom-jwt/#std-label-custom-jwt-authentication)\n\n```ts\nconst client = new MongoClient({\n  endpoint: \"https://data.mongodb-api.com/app/YOUR_APP_ID/endpoint/data/v1\",\n  dataSource: \"YOUR_CLUSTER_NAME\", // e.g. \"Cluster0\"\n  auth: {\n    jwtTokenString: \"YOUR_JWT\",\n  },\n});\n```\n\n### Define Schema Type\n\n```ts\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#### insertOne\n\n```ts\nconst insertId = await users.insertOne({\n  _id: new ObjectId(),\n  username: \"user1\",\n  password: \"pass1\",\n});\n```\n\n#### insertMany\n\n```ts\nconst insertIds = await users.insertMany([{\n  _id: new ObjectId(),\n  username: \"user1\",\n  password: \"pass1\",\n}, {\n  _id: new ObjectId(),\n  username: \"user2\",\n  password: \"pass2\",\n}]);\n```\n\n### Find\n\n#### findOne\n\n```ts\nconst user1_id = await users.findOne({\n  _id: new ObjectId(\"SOME OBJECTID STRING\"),\n});\n```\n\n#### find\n\n```ts\nconst allActiveUsers = await users.find({ active: true });\n```\n\n### Count\n\n#### countDocuments\n\n```ts\n// count of all active users\nconst count = await users.countDocuments({ active: true });\n```\n\n#### estimatedDocumentCount\n\n```ts\n// estimated count of all users\nconst estimatedCount = await users.estimatedDocumentCount();\n```\n\n### Aggregation\n\n```ts\nconst docs = await users.aggregate([\n  { $match: { username: \"many\" } },\n  { $group: { _id: \"$username\", total: { $sum: 1 } } },\n]);\n```\n\n### Update\n\n#### updateOne\n\n```ts\nconst { matchedCount, modifiedCount, upsertedId } = await users.updateOne(\n  { username: { $ne: null } },\n  { $set: { username: \"USERNAME\" } },\n);\n```\n\n#### updateMany\n\n```ts\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#### deleteOne\n\n```ts\nconst deleteCount = await users.deleteOne({ _id: insertId });\n```\n\n#### deleteMany\n\n```ts\nconst deleteCount = await users.deleteMany({ username: \"test\" });\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ferfanium%2Fatlas_sdk","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ferfanium%2Fatlas_sdk","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ferfanium%2Fatlas_sdk/lists"}