What I built
NERM (.NET + React.js + MongoDB) - Sample App - Use case Note App
Category Submission:
Think Outside the JS Box
App Link
Screenshots
Home
Note List
Create Note
Update Note
Delete Note
Description
Are you bored with the MERN stack? Let's move on to the NERM stack! :)
Link to Source Code
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
Deployment Pipelines
General
graph LR;
a[Github] --> b[Azure DevOps];
b --> c[AWS Elastic Beanstalk];
Azure DevOps
graph TD;
1[dotnet restore] --> a;
a["dotnet publish (zip)"] --> b[Upload Artifact];
b --> c[Beanstalk Task - Upload zip];
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
…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;
- Get by Id
var response = await _notesCollection.FindSync(note => note.Id == id).FirstAsync();
return response;
- 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;
- 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 };
- Delete
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.
Top comments (0)