-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore(beaking-changes): refactor and simplify codebase (#8)
* chore(beaking-changes): refactor and simplify codebase * fix(ci): format lockfile * feat(docs): enable switch for dark and light mode * feat(docs): add script for development * feat(db): backup with option fields * fix(docs): improve example * example: split backup controller
- Loading branch information
Showing
20 changed files
with
647 additions
and
391 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,25 +1,27 @@ | ||
## How to use with Typescript ? | ||
## Example backend application | ||
|
||
You can use the `MongoDbConnection` class from the package and you will be able to use the following methods: | ||
This is a simple example of a backend application using the MongoDB Atlas SDK for Node.js. The application is written in TypeScript and uses the Express framework. Check our user CRUD application on [Github](https://github.com/shivarm/mongodb-atlas-sdk/tree/main/examples/typescript) | ||
|
||
```typescript | ||
import express from 'express'; | ||
import dotenv from 'dotenv'; | ||
import { MongoDbConnection } from 'mongodb-atlas-sdk'; | ||
dotenv.config(); | ||
## Running the Example | ||
|
||
const mongoKit = new MongoDbConnection(process.env.DB_URI!); | ||
const app = express(); | ||
const PORT = process.env.PORT || 5000; | ||
You can run the example by following these steps: | ||
|
||
app.use(express.json({ limit: '10mb' })); | ||
Install Dependencies | ||
|
||
app.listen(PORT, () => { | ||
console.log('Server is running on http://localhost:' + PORT); | ||
mongoKit.connect(); | ||
}); | ||
```bash | ||
npm install | ||
``` | ||
|
||
## Example backend application | ||
Set Environment Variables | ||
Create a `.env` file in the root directory of the project and add the following environment variables: | ||
|
||
```env | ||
DB_URI= | ||
PORT=5000 | ||
``` | ||
|
||
Start the Server | ||
|
||
Check our user CRUD application on [Github](https://github.com/shivarm/mongodb-atlas-sdk/tree/main/examples/typescript) | ||
```bash | ||
npm run dev | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
[ | ||
{ | ||
"_id": "679a1343c406f835121d0f9d", | ||
"name": "John Doe", | ||
"email": "[email protected]", | ||
"age": 31, | ||
"__v": 0 | ||
} | ||
] |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import { Request, Response } from 'express'; | ||
import { Backup } from 'mongodb-atlas-sdk'; | ||
import { User } from '../model/userModel'; | ||
|
||
const backup = new Backup(); | ||
|
||
export const backupUser = async (req: Request, res: Response) => { | ||
try { | ||
const filePath = req.body.filePath; | ||
await backup.backupModel(User, filePath); | ||
res.status(200).json({ message: 'Backup completed successfully' }); | ||
} catch (err) { | ||
res.status(500).json({ message: 'Failed to backup data' }); | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.