{"id":20227707,"url":"https://github.com/andreabbondanza/mongo-atlas-client","last_synced_at":"2026-05-05T17:33:14.813Z","repository":{"id":163683549,"uuid":"639080947","full_name":"andreabbondanza/mongo-atlas-client","owner":"andreabbondanza","description":"A mongo atlas client with types for typescript","archived":false,"fork":false,"pushed_at":"2023-06-22T10:38:57.000Z","size":35,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-10-20T21:56:41.784Z","etag":null,"topics":["api","data-api","mongodb","mongodb-atlas","typescript"],"latest_commit_sha":null,"homepage":"","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/andreabbondanza.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,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2023-05-10T18:07:46.000Z","updated_at":"2023-07-08T18:31:08.000Z","dependencies_parsed_at":null,"dependency_job_id":"9b1344a4-39e1-439f-b207-9abba5f35b50","html_url":"https://github.com/andreabbondanza/mongo-atlas-client","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/andreabbondanza/mongo-atlas-client","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/andreabbondanza%2Fmongo-atlas-client","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/andreabbondanza%2Fmongo-atlas-client/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/andreabbondanza%2Fmongo-atlas-client/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/andreabbondanza%2Fmongo-atlas-client/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/andreabbondanza","download_url":"https://codeload.github.com/andreabbondanza/mongo-atlas-client/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/andreabbondanza%2Fmongo-atlas-client/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":32660338,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-05-05T11:29:49.557Z","status":"ssl_error","status_checked_at":"2026-05-05T11:29:48.587Z","response_time":54,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.5:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"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":["api","data-api","mongodb","mongodb-atlas","typescript"],"created_at":"2024-11-14T07:26:12.029Z","updated_at":"2026-05-05T17:33:14.796Z","avatar_url":"https://github.com/andreabbondanza.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# mongo-atlas-client\n\nFind it on [NPM](https://www.npmjs.com/package/mongo-atlas-client)\n\n## The need\n\nI needed a simple way to interact with the [MongoDB Atlas DATA-API](https://www.mongodb.com/docs/atlas/api/data-api-resources/) using the apikey and using the mongodb types, with typescript. Additionally, I took the opportunity to learn how to publish pure ESM modules to npm.\n\n## The data you need to use it\n\nYou'll forgive me if I'll assume you don't know how to use the data-api, but I'll assume you know how to use mongodb. If you don't, you can learn it [here](https://www.mongodb.com/try/download/community). When you create a project, you also create a cluster (datasource) and a database. After you've done this, you'll be able to enable the **data api** to use the database via https request instead the directly connection to the database. \n\nTo enable the **data api** you have to click on the _DATA API_ item under the _SERVICES_ group in the left bar menu. Then, you need to click on the **Create API KEY** button. You'll be asked to give a name to the key and to confirm the creation. After you have to save your key somewhere safe, because you won't be able to see it again. You'll receive also the endpoint url, that you'll need to use the api.\n\nSo, the data you'll get and you'll need to use this library are:\n- the **endpoint url**\n- the **api key**\n- the **datasource**\n- the **database**\n\nConnection data class\n```typescript\n/**\n * ConnectionData class\n */\nexport class ConnectionData\n{\n    /**\n     * The atlas data source, should be the cluster.\n     */\n    public dataSource: string;\n    /**\n     * The database to query.\n     */\n    public database: string;\n    /**\n     * The api key to use.\n     */\n    public apikey: string;\n    /**\n     * The atlas end point to use.\n     */\n    public atlasEndPoint: string;\n\n    /**\n     * Constructor\n     * @param config the configuration for the query\n     */\n    constructor(config: { dataSource: string, database: string, apikey: string, atlasEndPoint: string}) {\n        this.dataSource = config.dataSource;\n        this.database = config.database;\n        this.apikey = config.apikey;\n        this.atlasEndPoint = config.atlasEndPoint;\n    }\n}\n```\n\n## Dependency Injection\n\nTo allow to use your favorite http client library, when you initialize the _Client_ class, you can pass a callback that use your http client to make the request. The callback must return a string via promise that resolve to the response body. The callback will receive:\n- the endpoint (url with the action);\n- the body;\n- the headers;\n- the stringify function for with the EJSON support;\n- the action (find, findOne, deleteOne, etc.)\n\nHere the type request:\n\n```typescript\nexport type Request = (url: string, body: any, headers: any, (obj: any) =\u003e EJSON.stringify(obj), action: Actions) =\u003e Promise\u003cstring\u003e\n```\n\nTO the client you can also pass a log callback, if not, it will be used the console.log function\n\n## Responses\n\nThe responses types are the same of the mongodb types from MongoDB [API responses](https://www.mongodb.com/docs/atlas/api/data-api-resources/), so you can use them directly in your code. \n\n```typescript\n\nexport interface IMongoFindOneResponse\u003cT\u003e\n{\n    /**\n     * The document that was found.\n     */\n    document: T;\n}\n\nexport interface IMongoFindResponse\u003cT\u003e\n{\n    /**\n     * The documents that were found.\n     */\n    documents: T[];\n}\n\nexport interface IMongoInsertOneResponse\n{\n    /**\n     * The identifier that was inserted.\n     */\n    insertedId: string;\n}\n\nexport interface IMongoInsertManyResponse\n{\n    /**\n     * The identifiers that were inserted.\n     */\n    insertedIds: string[];\n}\n\nexport interface IMongoDeleteResponse\n{\n    /**\n     * The number of documents that were deleted.\n     */\n    deletedCount: number;\n}\n\nexport interface IMongoUpdateResponse\n{\n    /**\n     * The number of documents that were matched.\n     */\n    matchedCount: number;\n    /**\n     * The number of documents that were modified.\n     */\n    modifiedCount: number;\n    /**\n     * The identifier of the document that was upserted.\n     */\n    upsertedId: string;\n}\n\nexport interface IMongoReplaceResponse\n{\n    /**\n     * The number of documents that were matched.\n     */\n    matchedCount: number;\n    /**\n     * The number of documents that were modified.\n     */\n    modifiedCount: number;\n    /**\n     * The identifier of the document that was upserted.\n     */\n    upsertedId: string;\n}\n```\n\n## Usage\n\nThe library usage is quiet simple. Check the following example:\n\n```typescript\n\n// example user type from user collection\nclass User\n{\n    public name: string;\n    public surname: string\n    public age: number;\n    constructor(name: string, surname: string, age: number)\n    {\n        this.name = name;\n        this.surname = surname;\n        this.age = age;\n    }\n}\n\n\nasync function example()\n{\n    // set the connection data\n    const connectionData: ConnectionData = new ConnectionData({\n        dataSource: \"source\",\n        database: \"test\",\n        apikey: \"1234567890\",\n        atlasEndPoint: \"endpoint\"\n    });\n    // set the request callback with got library\n    const myRequest: Request = async (url: string, body: any, headers: any, stringify: (obj: any) =\u003e string, action: string) =\u003e\n    {\n        const response = await got.post(url, { body: stringify(body), headers });\n        return response.body;\n    };\n    // create the client\n    const client = new Client(connectionData, myRequest);\n    // find all users with age greater than 18\n    const users = await client.find\u003cUser\u003e(\"users\", { age: { $gt: 18 } });\n    if (users)\n        for (const user of users.documents)\n        {\n            console.log(`${user.name} ${user.surname} is ${user.age} years old`)\n        }\n    // create a new user\n    const userToAdd = new User(\"John\", \"Doe\", 21);\n    // insert the user\n    const insertResponse = await client.insertOne\u003cUser\u003e(\"users\", userToAdd);\n    if (insertResponse)\n        console.log(`Added user with id: ${insertResponse.insertedId}`);\n\n}\n```\n\nIn this example you can see the use of the library. \n1. We start defining the *connection data*;\n2. Then we define the request callback, that use the **got** library to make the request (but you can use whatever you want). \n3. Then we create the client and we use it to find all the users with age greater than 18.\n4. Then we create a new user and we insert it in the database.\n\nAs you can see, the library support the MongoDB filters and for the response it use the MongoDB response types.\n\n\n# NOTE ⚠️\n\nThis isn't a library for the API of **MONGO ATLAS Platform**, this library is for the **MONGO ATLAS DATA API**\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fandreabbondanza%2Fmongo-atlas-client","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fandreabbondanza%2Fmongo-atlas-client","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fandreabbondanza%2Fmongo-atlas-client/lists"}