DEV Community

Cover image for MongoDB Atlas Hackathon 2022 on DEV | NERM
Bervianto Leo Pratama
Bervianto Leo Pratama

Posted on • Updated on

MongoDB Atlas Hackathon 2022 on DEV | NERM

What I built

NERM (.NET + React.js + MongoDB) - Sample App - Use case Note App

Category Submission:

Think Outside the JS Box

App Link

App Demo Link

Screenshots

Home

Home

Note List

Note List

Create Note

Create Note

Update Note

Update Note

Updated Note

Delete Note

Delete Note

Deleted Note

Description

Are you bored with the MERN stack? Let's move on to the NERM stack! :)

Cat Dance GIF

Link to Source Code

GitHub logo bervProject / NERM

.NET + React + MongoDB

Note App

Stack:

.NET + React.js + MongoDB

Recommended IDE(s)

  • Visual Studio
  • Rider
  • Visual Studio Code

Run Command (CLI) - Development Mode

dotnet run --project .\NoteApp\ --launch-profile NoteApp
Enter fullscreen mode Exit fullscreen mode

Deployment Pipelines

General

graph LR;
 a[Github] --> b[Azure DevOps];
 b --> c[AWS Elastic Beanstalk];
Loading

Azure DevOps

graph TD;
 1[dotnet restore] --> a;
 a["dotnet publish (zip)"] --> b[Upload Artifact];
 b --> c[Beanstalk Task - Upload zip];
Loading

License

MIT

The MIT License (MIT)
Copyright © 2022 Bervianto Leo Pratama

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice
Enter fullscreen mode Exit fullscreen mode

Permissive License

MIT

Background

I want to learn .NET and MongoDB. I believe this challenge will be good for getting started.

How I built it

Well. I was just using MongoDB.Driver to connect my app with the MongoDB Atlas. Simple, right? :)

First thing first, I built the API. Easy query.

  • Find/Get All
            var filterBuilder = new FilterDefinitionBuilder<Note>();
            var response = await _notesCollection.FindAsync(filterBuilder.Empty);
            var responseData = new List<Note>();
            while (response != null && (await response.MoveNextAsync()))
            {
                responseData.AddRange(response.Current);
            }

            return responseData;
Enter fullscreen mode Exit fullscreen mode
  • Get by Id
            var response = await _notesCollection.FindSync(note => note.Id == id).FirstAsync();
            return response;
Enter fullscreen mode Exit fullscreen mode
  • Create/Insert
            var note = new Note
            {
                Id = Guid.NewGuid(),
                Title = request.Title,
                Description = request.Description,
                CreateDateTimeOffset = DateTimeOffset.Now,
                UpdateDateTimeOffset = DateTimeOffset.Now
            };
            await _notesCollection.InsertOneAsync(note);
            return note;
Enter fullscreen mode Exit fullscreen mode
  • Update
            var filterBuilder = new FilterDefinitionBuilder<Note>();
            var updateBuilder = new UpdateDefinitionBuilder<Note>();
            var updateDefinition = updateBuilder
                .Set(x => x.Title, request.Title)
                .Set(x => x.Description, request.Description)
                .Set(x => x.UpdateDateTimeOffset, DateTimeOffset.Now);
            await _notesCollection.UpdateOneAsync(filterBuilder.Eq(x => x.Id, id), updateDefinition);
            return new { Id = id };
Enter fullscreen mode Exit fullscreen mode
  • Delete
            var filterBuilder = new FilterDefinitionBuilder<Note>();
            await _notesCollection.DeleteOneAsync(filterBuilder.Eq(x => x.Id, id));
            return new { Id = id };
Enter fullscreen mode Exit fullscreen mode

Secondly, let's break the client code. I won't tell you the long story. :)

Third, test and deploy. Let's go! Thanks to AWS Elastic Beanstalk for hosting my app.

Additional Resources/Info

Don't worry if you have any doubts. Feel free to give feedback here.

Feedback Time GIF

Top comments (0)