Intro to MongoDB with C# - Learn what NoSQL is, why it is different than SQL and how to use it in C#

preview_player
Показать описание
MongoDB is a NoSQL database type that works really well with C#. Learn how to perform CRUD operations, how to modify the schema of a document, and how to get just the data you need back.

This covers MongoDB 4, which is now ACID-compliant and is a direct competitor for major relational databases like Microsoft SQL. See just how easy it is to get started.

Thanks to Ralfs HBK for the channel breakout:
0:00 - Intro
1:27 - Setup: Mongo DB Community Server installation
8:06 - Creating Demo Core Console App
9:35 - MongoDB NuGet
11:04 - Mongo CRUD
12:50 - "Connection string"
14:50 - Connecting to database
17:13 - Data storage in MongoDB
24:39 - Inserting data in database
28:07 - Changing data set structure
30:45 - Inserting different data set in the table and benefit of NoSQL
36:52 - Retrieving data form database
42:00 - MongoDB Query
48:40 - Update and delete methods
54:28 - Insert or Update record
59:00 - Delete record
59:42 - Returning different data model from database record
1:02:55 - Demo code clean up
1:03:20 - MongoDB when and why?
1:15:15 - Summary and concluding remarks
Рекомендации по теме
Комментарии
Автор

Video is uploaded 5 minutes ago and someone already clicked a dislike. Hey man, you even did not watch this!!!

Thank you Tim for this tutorial. Thumb up!

johnconnor
Автор

Awesome introduction to NoSQL for .NET developers! Thanks as always and best wishes Tim.

ben.thornhill
Автор

Dude, your videos are great. Neither rushed nor slow, and including all of the salient information a newbie to a subject needs. Kudos!

Evan-zjmt
Автор

Thank you for a good introduction, Tim. Been using MSSQL for many years and knows it very well. For me this was a first look at NoSQL, and it looks very very interesting! At first it feels very uncomfortable with the loose data structure but it really makes a lot of sense. Just the fact that the termonology is "documents" rather than "tables" makes so much sense; love that we're simply just storing the data as it actually is instead of joining tables and all that.

codecomposer
Автор

Mr. Corey, thank you. I am accepted to an internship position in an international company called Exadel. The knowledge you are sharing in YouTube is priceless. I am still learning from your content and plan to one your paid courses once I receive my salary as a .net developer.
Your student from Uzbekistan :)

DasturlashniOrganamiz
Автор

Hello Tim,
You have a logical error in this video starting from the time position 1:00:00, when you tried to bring and use new NameModel class. It is working for you because you deleted the last record that has PrimaryAddress just before you introduced NameModel. If you actually have couple existing records in DB, some of them have only FirstName and LastName (and Id for sure) and some have FirstName, LastName and PrimaryAddress, you won't be able to use NameModel as you just did. You will have unhandled exception in the line:
return collection.Find(new BsonDocument()).ToList();
saying: 'Element 'PrimaryAddress' does not match any field or property of class MongoDBDemo.NameModel.'


So you cannot "narrow down" your objects so easily if you actually have additional data in the MongoDB, you will have to use some conversion.

artemprokhorov
Автор

Thank you Tim Corey, you explained that mongoDb is faster than sql perfectly. Have learned something new!

iamtheone
Автор

0:00 - Intro
1:27 - Setup: Mongo DB Community Server installation
8:06 - Creating Demo Core Console App
9:35 - MongoDB NuGet
11:04 - Mongo CRUD
12:50 - "Connection string"
14:50 - Connecting to database
17:13 - Data storage in MongoDB
24:39 - Inserting data in database
28:07 - Changing data set structure
30:45 - Inserting different data set in the table and benefit of NoSQL
36:52 - Retrieving data form database
42:00 - MongoDB Query
48:40 - Update and delete methods
54:28 - Insert or Update record
59:00 - Delete record
59:42 - Returning different data model from database record
1:02:55 - Demo code clean up
1:03:20 - MongoDB when and why?
1:15:15 - Summary and concluding remarks

RalfsBalodis
Автор

Thanks for this. It really helped me understand MongoDB and when to use it. I've been using MSSQL for 20 years. I don't see using mongodb for anything at work yet, but I'm testing it with a app at home.

AnalogDave
Автор

Tim Corey Very useful tutorial. Learned all the basics for a NoSql database in just 1 hour. Keep up the good work!

emirhandemirci
Автор

I am learning NoSQL for the first time and its the best video have found it very informative and in very understandable tone. MongoDB is very good NoSQL option with .NET Core. Thanks

anshulchoure
Автор

Thanks for another great video, Tim. I'd just like to point out that the mongo driver is quite clever and can do lambda expressions within Find() and other methods. So for example things like this are perfectly possible:


return await db.Find(x => x.UserId == userId)
.Skip(page * pagesize)
.Limit(pagesize)
.ToListAsync();

FakirCB
Автор

Need to decorate the NameModel a bit in order to get it to work now. 1:01:19


public class NameModel
{
[BsonId]
public Guid Id { get; set; }
public string FirstName { get; set; }
public string LastName { get; set; }
}

xando
Автор

This is a great Video, I've done a introductory course in MongoDB, but as you said it right "this is my new tool... then now what?" even they in that course just tell you about using it with console and Atlas so this is a very good piece of material to integrate it with C# Thanks a lot.

mirragemelkyr
Автор

Another terrifically educational video. Thanks for taking the time to produce and post. Always look forward to your content.

ohmyohmyohmy
Автор

For all free tutorial in youtube, this is great

alvinbernardo
Автор

UpsertRecord<T> with the ReplaceOne, 52:39, is obsolete in new Mongo installs. Need to replace "new BsonDocument..." with a filter on the ID

public void UpsertRecord<T>(string table, Guid id, T record)
{
// Create the collection
var collection = db.GetCollection<T>(table);
// Create the filter
var filter = Builders<T>.Filter.Eq("Id", id);
// Replace the record via an upsert
// Upsert is an update if the filter finds something or
// an insert if there is nothing matching
collection.ReplaceOne(
filter,
record,
new ReplaceOptions { IsUpsert = true });
}

xando
Автор

As usual, a very, very nice video. Got a project on this noSQL thing and had no idea where to start. Was most-delighted when I saw you did a video because I knew it was going to be the best place to start. Took me through all the CRUD operations and can't believe how simple it is in C#. The Cosmo Db in Azure is a "fake" MongoDb. It offers various "API"s, one of them is Mongo. So, for the most part, you send it normal Mongo instructions and it responds, just like Mongo. Cool. And, only costs about $5-$6 a month to get started. Connection String inserts just like you said it would in your video. I am a SQL Server bigot but am most-happy about being able to add this to my resume and quiver. Yeah, I can see the positives. Did have 2 questions. One, more complex filter usage for query, upsert and delete. Two, can you remove a property in a "document" once added. Not the value of the property but the property itself. Say you added something and company policy has changed and that property, from each record ("document") has to be removed for legal reasons. Also, I'm curious, it's so fast? There has to be indexing then. Is it/are they clustered or non-clustered? Would be very surprised if there were no indexes. I found the constant reference to Models interesting. So non-structured and yet the model usage. Not sure how to wrap my head around that but, coming from a very-structured world, I find this really easy going. Thanks again Tim. All the best. Awesome.

georgetuccio
Автор

Thanks Tim. Very nice introduction to MongoDB and NoSQL world.

Автор

Tq for your short and sweet video about how to use MongoDB in C#, it was handy.

amirdaydaychallenge