MongoDB Atlas Hackathon 2022 on DEV | NERM
Tags: atlashackathon22, mongodb, dotnet, react
Published: 2022-11-30 19:28:57

## 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](http://noteapp-env-1.eba-33zrhb2m.ap-southeast-3.elasticbeanstalk.com/note-list)

### Screenshots

#### Home

![Home](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/wkt4s06t24ym40t5q09i.png)

#### Note List

![Note List](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/yvygfgvjp3zhapwdutwu.png)

#### Create Note

![Create Note](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ldh00v402qbm5v1bov4l.png)

#### Update Note

![Update Note](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/5yxsar5ydfjgn0u5xkre.png)

![Updated Note](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/68r9mqp2yhidz5arvlb4.png)

#### Delete Note

![Delete Note](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/hrmkvjd8tc4h2rq7oxwd.png)

![Deleted Note](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/b7rxhfw37obr46c0bniq.png)

### Description

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

![Cat Dance GIF](https://media.giphy.com/media/BK1EfIsdkKZMY/giphy.gif)

### Link to Source Code

{% github bervProject/NERM %}

### 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

```csharp
            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;
```

* Get by Id

```csharp
            var response = await _notesCollection.FindSync(note => note.Id == id).FirstAsync();
            return response;
```

* Create/Insert

```csharp
            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;
```

* Update

```csharp
            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 };
```

* Delete

```csharp
            var filterBuilder = new FilterDefinitionBuilder<Note>();
            await _notesCollection.DeleteOneAsync(filterBuilder.Eq(x => x.Id, id));
            return new { Id = id };
```

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](https://media.giphy.com/media/H3NF3JvE1mOsOXb8l3/giphy.gif)