Introduction

In case you missed the other days:
Day 1 Deep Dive
Day 2 Deep Dive with MongoDB
Day 2 Deep Dive with MongoDB

Tonight's posting is shifting a bit from my original plan of using JSON Storage in favor of testing MongoDB with ASP.NET Core and comparing it to SQL Server/ASP.NET Core and Node.js/MongoDB.

Prerequisites

At this point I am going to assume MongoDB is up and running, if you do not, check my first day post for details on how to get it up and running.
For this deep dive, the only new element I needed to add were the NuGet package reference for the MongoDB.Driver. Because I am using ASP.NET Core instead of 4.6.2 I needed to download 2.3.0-rc1.

Regardless, the package also installs MongoDB.Bson and MongoDB.Driver.Core NuGet packages as well.

WebAPI Code

After the NuGet package installation above, I removed the Entity Framework code and replaced it with the MongoDB that mimics what I had done in JavaScript a few nights ago (thus the huge simliarities:

[HttpGet] public async Task Get(int id) { var client = new MongoClient("mongodb://localhost"); var database = client.GetDatabase("day2innode"); var collection = database.GetCollection("posts"); var document = new BsonDocument { { "id", id }, { "likes", 2 } }; await collection.InsertOneAsync(document); return "OK"; }

Performance

After last night's SQL Server performance being pretty even with MongoDB at least in this simple test I was curious what the MongoDB driver for .NET would be like in terms of performance:

Not truly comfortable with the results, I re-ran the benchmarks several times and all were within 2% of the previous results. Interesting to say the least that .NET at least in this scenario is faster across the board than a Node.js implementation.

Next up...

Tomorrow I hope to see if maybe there are some Node.js optimizations I can apply admitting that before Tuesday night I had never messed with Node.js before.
Lastly, all of the code thus far is committed on GitHub.
TAGS
none on this post