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

  Рет қаралды 138,339

IAmTimCorey

IAmTimCorey

Күн бұрын

Пікірлер: 567
@johnconnor9787
@johnconnor9787 5 жыл бұрын
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!
@NorbertWebDev
@NorbertWebDev 5 жыл бұрын
Lol, dident even remake the dislike, there are some bad people runing round the internet :)))
@IAmTimCorey
@IAmTimCorey 5 жыл бұрын
Yeah, I saw that. The funny thing is that KZbin cares about engagement. The more engagement a video gets (likes, dislikes, comments), the higher they rank it so technically, that person is helping me just a bit. :-)
@23myiah
@23myiah 5 жыл бұрын
Yes, very poor show to dislike without even viewing. Thank you Tim for giving us your time and knowledge.
@pylvr8021
@pylvr8021 5 жыл бұрын
She must be an Ex lol
@ben.thornhill
@ben.thornhill 5 жыл бұрын
Awesome introduction to NoSQL for .NET developers! Thanks as always and best wishes Tim.
@IAmTimCorey
@IAmTimCorey 5 жыл бұрын
Thank you!
@RalfsBalodis
@RalfsBalodis 4 жыл бұрын
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
@IAmTimCorey
@IAmTimCorey 4 жыл бұрын
Thank you!
@Evan-zj5mt
@Evan-zj5mt 5 жыл бұрын
Dude, your videos are great. Neither rushed nor slow, and including all of the salient information a newbie to a subject needs. Kudos!
@IAmTimCorey
@IAmTimCorey 5 жыл бұрын
Thank you!
@codecomposer88
@codecomposer88 3 жыл бұрын
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.
@IAmTimCorey
@IAmTimCorey 3 жыл бұрын
Glad it was helpful!
@iamtheone9670
@iamtheone9670 Жыл бұрын
Thank you Tim Corey, you explained that mongoDb is faster than sql perfectly. Have learned something new!
@IAmTimCorey
@IAmTimCorey Жыл бұрын
It can be faster. That doesn't mean it is always the better choice. There are always tradeoffs. I'm glad it was valuable.
@artemprokhorov506
@artemprokhorov506 5 жыл бұрын
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.
@IAmTimCorey
@IAmTimCorey 5 жыл бұрын
I forgot to show that. Sorry about that. The solution is to put a [BsonIgnoreExtraElements] on the top of your model and it will work. I meant to show it. Thanks for pointing it out.
@DasturlashniOrganamiz
@DasturlashniOrganamiz 4 жыл бұрын
Mr. Corey, thank you. I am accepted to an internship position in an international company called Exadel. The knowledge you are sharing in KZbin 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 :)
@IAmTimCorey
@IAmTimCorey 4 жыл бұрын
Awesome! I am glad I was able to be a part of your journey.
@emirhandemirci6677
@emirhandemirci6677 4 жыл бұрын
Tim Corey Very useful tutorial. Learned all the basics for a NoSql database in just 1 hour. Keep up the good work!
@IAmTimCorey
@IAmTimCorey 4 жыл бұрын
Glad it was helpful!
@ohmyohmyohmy2
@ohmyohmyohmy2 5 жыл бұрын
Another terrifically educational video. Thanks for taking the time to produce and post. Always look forward to your content.
@IAmTimCorey
@IAmTimCorey 5 жыл бұрын
You are welcome.
@xando81
@xando81 4 жыл бұрын
UpsertRecord 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(string table, Guid id, T record) { // Create the collection var collection = db.GetCollection(table); // Create the filter var filter = Builders.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 }); }
@IAmTimCorey
@IAmTimCorey 4 жыл бұрын
Thanks for sharing.
@shittygamer_jamaican
@shittygamer_jamaican 4 жыл бұрын
Thanks a lot.
@steejayk
@steejayk 5 жыл бұрын
Your video is NEVER too long!
@IAmTimCorey
@IAmTimCorey 5 жыл бұрын
Thanks!
@anshulchoure7521
@anshulchoure7521 4 жыл бұрын
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
@IAmTimCorey
@IAmTimCorey 4 жыл бұрын
Glad it was helpful!
@xeyalteyyubov1175
@xeyalteyyubov1175 2 жыл бұрын
Thanks, Tim that is one of the most beautiful no SQL videos on youtube.
@IAmTimCorey
@IAmTimCorey 2 жыл бұрын
Thank you!
4 жыл бұрын
Thanks Tim. Very nice introduction to MongoDB and NoSQL world.
@IAmTimCorey
@IAmTimCorey 4 жыл бұрын
Glad it was helpful!
@austinmudadi9178
@austinmudadi9178 9 күн бұрын
Impressive, thanks Tim. Always the best!
@IAmTimCorey
@IAmTimCorey 8 күн бұрын
You are welcome.
@shrimpsnplants
@shrimpsnplants 5 жыл бұрын
"That's the basic structure of MongoDB meaning that isn't really a structure" you made my day :D
@IAmTimCorey
@IAmTimCorey 5 жыл бұрын
I'm glad you enjoyed it.
@AnalogDave
@AnalogDave 4 жыл бұрын
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.
@IAmTimCorey
@IAmTimCorey 4 жыл бұрын
Glad it was helpful!
@mirragemelkyr
@mirragemelkyr 4 жыл бұрын
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.
@IAmTimCorey
@IAmTimCorey 4 жыл бұрын
Glad it was helpful!
@anton_zhernosek
@anton_zhernosek 2 жыл бұрын
Even though I don't like how long the videos are, they're on a whole other level of usefulness compared to any other online tutorial. You're a godsend, Tim
@IAmTimCorey
@IAmTimCorey 2 жыл бұрын
I am glad you find them valuable.
@xando81
@xando81 4 жыл бұрын
Need to decorate the NameModel a bit in order to get it to work now. 1:01:19 [BsonIgnoreExtraElementsAttribute] public class NameModel { [BsonId] public Guid Id { get; set; } public string FirstName { get; set; } public string LastName { get; set; } }
@IAmTimCorey
@IAmTimCorey 4 жыл бұрын
Thanks for sharing.
@alexcyoung
@alexcyoung 5 жыл бұрын
Great video Tim! And a nice, simple way of handling CRUD operations without requiring models to inherit from a common 'entity' base class.
@IAmTimCorey
@IAmTimCorey 5 жыл бұрын
Thanks. I considered a common model base but decided against it for this video.
@FakirCB
@FakirCB 5 жыл бұрын
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();
@IAmTimCorey
@IAmTimCorey 5 жыл бұрын
Awesome! Thanks for sharing.
@taha5871
@taha5871 4 жыл бұрын
Awesome video explaining how u use MongoDB with C# , thanks so much 💙💙
@IAmTimCorey
@IAmTimCorey 4 жыл бұрын
You're very welcome!
@Randomness-rl8lv
@Randomness-rl8lv 3 жыл бұрын
Wow awesome video as always Tim! Since you asked at the end of your video, perhaps you can make a subsequent video explaining / integrating Microsoft Identity with MongoDB!
@tomthelestaff-iamtimcorey7597
@tomthelestaff-iamtimcorey7597 3 жыл бұрын
We appreciate the suggestion and I have added it to Tim's list.
@CaatjuhNL1
@CaatjuhNL1 4 жыл бұрын
One of the best tutorial I have followed so far! Thank you for your time and effort for making the video. Background explanation was also clear and nice to listen to. Keep it up!
@IAmTimCorey
@IAmTimCorey 4 жыл бұрын
You're very welcome!
@alvinbernardo9551
@alvinbernardo9551 4 жыл бұрын
For all free tutorial in youtube, this is great
@IAmTimCorey
@IAmTimCorey 4 жыл бұрын
Thank you!
@georgetuccio6053
@georgetuccio6053 5 жыл бұрын
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.
@IAmTimCorey
@IAmTimCorey 4 жыл бұрын
I will be doing other videos shortly using MongoDB. As for removing the property, you should be able to pull down the record and then save it without the property. As for the speed, its speed comes primarily from the fact that all of the data is together instead of pulling from separate locations. One quick note: I originally thought you could drop the units to 100 for MongoDB but you cannot so the smallest database you can get is 400 units, which costs $25/month. Just be careful of that.
@amirday2daychallenge
@amirday2daychallenge 5 жыл бұрын
Tq for your short and sweet video about how to use MongoDB in C#, it was handy.
@IAmTimCorey
@IAmTimCorey 5 жыл бұрын
You are most welcome. Thanks for watching.
@amoljawalkar6273
@amoljawalkar6273 2 жыл бұрын
One of the best tutorial found online. Thank you so much
@tomthelestaff-iamtimcorey7597
@tomthelestaff-iamtimcorey7597 2 жыл бұрын
Your endorsement is much appreciated! Thank you for helping to spread the word.
@umairraza192
@umairraza192 3 жыл бұрын
Excellent Tutorial ! I like the way you create these these common generic functions so we can directly use them with our models. Thank you very much for your effort and time. Stay blessed .
@IAmTimCorey
@IAmTimCorey 3 жыл бұрын
You're very welcome!
@Dumah79
@Dumah79 4 ай бұрын
Your explations are best Tim just thank you.
@IAmTimCorey
@IAmTimCorey 4 ай бұрын
You are welcome.
@pampula9327
@pampula9327 5 жыл бұрын
Awesome guide and so easy to follow. Thank you very much Tim! I would love to see maybe simple CRUD web app using net core api with MongoDB. That would be really awesome. I am hard core beginner in C# and this was so easy to follow.
@IAmTimCorey
@IAmTimCorey 5 жыл бұрын
I'm glad it was so easy to follow. I'll add your suggestion to the list.
@toshitosliba4737
@toshitosliba4737 2 жыл бұрын
Hello, I started to develop my game like a year and 3 months ago, I am alone doing this, no easy feat let me tell you and I am using Unity. I planned and divided my project in phases, first I would develop the base of the game as single player, then later on I would use the asset Fishnetworking and convert my single player game into a multiplayer. And after I finished converting my systems I hit to a point where I would need a database. For example I have features such as character creation, also I want to make a guild system and a group system. Besides of the other systems, as they need a database as well to save data, so I started to look and found about mongoDB, at first I wanted to go for mySQL, but I saw that NoSQL might be a better fit for my game. And so I started, but to me it's kind overwhelming, because I am just starting on the database field. And thank goodness I found your video, it goes to the point and you actually created a helper class to kind interact when I want to manage my database in some way. I am so thankful for that, this video helped me alot :)
@dwain.d
@dwain.d 5 жыл бұрын
Thanks Tim. I'm fresh out of a programming qualification and often used your videos to further understand things, and now am currently building my first free lance production application. The application has a requirement for a database so this this video appearing is very timely. My first prototype used SQL but it felt like overkill for the data structure. I have heard a lot about Mongo from current web stacks (MEAN, MERN etc) but didn't realise I could use it from C#. I look forward to trying this out instead and seeing how it goes for my application.
@IAmTimCorey
@IAmTimCorey 5 жыл бұрын
Excellent. Let us know how it goes.
@Diploidus
@Diploidus 4 жыл бұрын
Hi pls, fix me if I wrong. The query "LadAllRecords" occasionally worked for NameModel collection, just because the table didn't contain documents with Address or DOB at this moment. Probably you forgot to decorate class NameModel with [BsonIgnoreExtraElements]?
@IAmTimCorey
@IAmTimCorey 4 жыл бұрын
Yep, that will work.
@codecomposer88
@codecomposer88 3 жыл бұрын
Thank you! Just what I was looking for.
@AhmetYigiter
@AhmetYigiter 5 жыл бұрын
I love your videos... My English is max. intermediate but I understood everything because of your great and clean vocalization. Of course thanks for the information too...
@IAmTimCorey
@IAmTimCorey 5 жыл бұрын
Awesome!
@Randomness-rl8lv
@Randomness-rl8lv 4 жыл бұрын
Hi Tim thank you so much for you video's!! You are a online hero!! It would be awesome if you could make video where you integrate .Net Core Identity to a MongoDB back end (like in this video). Thank you so much!!
@IAmTimCorey
@IAmTimCorey 4 жыл бұрын
I will add it to the list. Thanks for the suggestion.
@zbigniewcwiakalski7253
@zbigniewcwiakalski7253 7 ай бұрын
42:55 - if it is db.GetCollection(table) does it mean even though you want to get one single record (by id) does it load whole collection ? Does it fetch the whole table even if I want 1 record from db ?
@Tiagorockman
@Tiagorockman 3 жыл бұрын
Top one best video i have seen about mongodb c#. Thanks alot for share!
@tomthelestaff-iamtimcorey7597
@tomthelestaff-iamtimcorey7597 3 жыл бұрын
His goal is to make learning easier. It appears he is doing just that!
@khemo240
@khemo240 5 жыл бұрын
Tim you came in clutch with this tutorial....I just started using the database so your intro will be very helpful... I'm from Jamaica so the Grammer may differ from standard English 😅
@IAmTimCorey
@IAmTimCorey 5 жыл бұрын
Excellent!
@T-par-T
@T-par-T 4 жыл бұрын
Mark my words: Tim is the best!
@IAmTimCorey
@IAmTimCorey 4 жыл бұрын
Thanks!
@codecomposer88
@codecomposer88 3 жыл бұрын
Are there equivalents in MongoDB (or NoSQLs in general) to SQL views, stored procedures and triggers? Does it even make any sense to think in these terms when it comes to NoSQL?
@IAmTimCorey
@IAmTimCorey 3 жыл бұрын
As far as views and stored procedures, no not really. There doesn't need to be because we treat data differently. We don't focus on relationships, we focus on complete documents. We approach the problem differently, so we end up using different solutions. There can be triggers in a NoSQL database. For instance, an Azure Function can be triggered from a data change event in a CosmosDB database.
@codecomposer88
@codecomposer88 3 жыл бұрын
@@IAmTimCorey Thank you!
@rongliao9255
@rongliao9255 4 жыл бұрын
Great tutorial! NoSQL database can be a great choice for the new projects!
@IAmTimCorey
@IAmTimCorey 4 жыл бұрын
Thanks!
@cbirchy87
@cbirchy87 4 жыл бұрын
Hi Tim, It appears the ReplaceOne has been made obsolete. What the is new way of doing the same thing for an Upsert?
@nestle579
@nestle579 4 жыл бұрын
UpdateOptions was replaced by ReplaceOptions. This is my modified implementation: public void UpsertRecord(string table, Guid id, T reccord) { var collection = db.GetCollection(table); var result = collection.ReplaceOne( new BsonDocument("_id", new BsonBinaryData(id, GuidRepresentation.Standard)), reccord, new ReplaceOptions { IsUpsert = true }); }
@jakubondrak1922
@jakubondrak1922 5 жыл бұрын
Hi Tim, awesome video again. I really like your channel. This was the first time I come across with MongoDB. Do you have or plan another videos about it? I'm planning to create an application and MongoDB look promising. Thanks, Jakub
@IAmTimCorey
@IAmTimCorey 5 жыл бұрын
I do plan on using it in other videos. It will also be one of the database types in my Foundation in C# module 8 course on data access. That comes out this month.
@KouroushMetal
@KouroushMetal 5 жыл бұрын
Very Good One. Thanks. Big questions are Group, Index, Search Speed On non-Id columns, and datagridview datasource with all these not consistent documents.
@IAmTimCorey
@IAmTimCorey 5 жыл бұрын
Thanks for the suggestions.
@cameronroberson5627
@cameronroberson5627 4 жыл бұрын
Hey Tim Corey, really great video here! I had a few questions: First, how would we get a Guid in a real world situation? It looks like they are user specific, and in your video you grabbed it from the console if I remember correctly. @46:05 Is Guid needed for security? Could we just find a user based on UserName? Thanks for your video,
@IAmTimCorey
@IAmTimCorey 4 жыл бұрын
I am using the developer tools to inspect the objects I have in memory (3 PersonModel objects). Inside of those objects are the GUIDs. So, if you wanted to access that data, you just pull it out of the object (or use the object). No need to involve the developer tools. I was just showing you the values instead of printing them to the Console. As for needing the GUID, you use that for easy lookup of the record. You can query by other values, but the GUID will be unique and is indexed.
@cameronroberson5627
@cameronroberson5627 4 жыл бұрын
@@IAmTimCorey Great answer. Thanks Tim
@mrfreddie04p
@mrfreddie04p 5 жыл бұрын
1:01:53 Hi, Tim! When I tried to load records into List, I got the following error "'Element 'dob' does not match any field or property of class MongoDBDemo.NameModel.'". So, for me adding just the "id" field did not solve the problem and the system looked for all fields coming from the database to be mapped. I determined that the exception was triggered by ToList() call. Any idea why it behaved differently in my environment? [Edit] Just figured it out. Needed to decorate NameModel with [BsonIgnoreExtraElements]. Still interesting that it worked for you. Perhaps the Mongo Driver NuGet package version - I used 2.9.2.
@IAmTimCorey
@IAmTimCorey 5 жыл бұрын
That's interesting. Not sure why you had that error.
@Tajdev
@Tajdev 3 жыл бұрын
Great Video. Please do advance Level video also which covers Aggregation, ACID AND Triggers.
@tomthelestaff-iamtimcorey7597
@tomthelestaff-iamtimcorey7597 3 жыл бұрын
We appreciate the suggestion and I have added it to Tim's list.
@DamianWalczak
@DamianWalczak 4 жыл бұрын
Thank you Tim that was very informative
@IAmTimCorey
@IAmTimCorey 4 жыл бұрын
You are welcome.
@HelmutPolischer
@HelmutPolischer 3 жыл бұрын
The compiler now reports a warning with the line new BsonDocument("_id", id) BsonValue.implicit operator BsonValue(Guid)' is obsolete: 'Use the BsonBinaryData constructor instead and specify a Guid representation. Following this advice, the method becomes the following and compiles without a warning. public void UpsertRecord(string table, Guid id, T record) { var collection = GetCollection(table); var filter = new BsonDocument("_id", new BsonBinaryData(id, GuidRepresentation.Standard)); collection.ReplaceOne(filter, record, new ReplaceOptions { IsUpsert = true }); }
@IAmTimCorey
@IAmTimCorey 3 жыл бұрын
Thanks for sharing.
@touseef.awan1
@touseef.awan1 4 жыл бұрын
Thank you Tim. You are best.
@IAmTimCorey
@IAmTimCorey 4 жыл бұрын
You are very welcome
@sepwille7793
@sepwille7793 4 жыл бұрын
Thanks for the very useful tutorial Tim! However, i am struggling to retrieve objects who are child of one array object. So i have one object which is an array, in this array are multiple nested objects of different classtypes... Do you have an idea how to find the right 'nested objects?
@IAmTimCorey
@IAmTimCorey 4 жыл бұрын
I am not sure I see what the problem is. If you load an object, you will load all of the nested objects inside of it.
@johnbond6806
@johnbond6806 4 жыл бұрын
I have the same issue, I would like to just update a child (Object) of an document, because loading all the children from the document seems a little bit inefficient. The thing is that I can't access the child by using its id, it seems like mongodb tries to search in the parents but doesn't search in the children. Is there a way to search ID in children and update it or search the parent by ID and then update ONLY a certain child?
@jaspercoleman3269
@jaspercoleman3269 3 жыл бұрын
Great video content as always. Thanks for sharing the knowledge, it keeps me motivated to learn more.
@IAmTimCorey
@IAmTimCorey 3 жыл бұрын
You are welcome.
@summerbreeze25syria
@summerbreeze25syria 4 жыл бұрын
Thank you very much. At the end, you mentioned when to use MongoDB and you said it has this issue of transactions, would it be suitable to use MongoDB in an online shop application?
@IAmTimCorey
@IAmTimCorey 4 жыл бұрын
Definitely. MongoDB can be used (at this point) anywhere that a relational database (like SQL) can be used. It is different and you have to approach things differently, but MongoDB is fully ACID compliant.
@space_orphan
@space_orphan 4 жыл бұрын
I'm trying to implement the UpsertRecord method, and I'm running into problems when constructing the BsonDocument. When I try new BsonDocument("_id", id) I get an error that says 'BsonValue.implicit operator BsonValue(Guid)' is obsolete: 'Use the BsonBinaryData constructor instead and specify a Guid representation.' I tried to troubleshoot this problem, but I'm not very experienced and can't seem to figure it out. Any help would be much appreciated!
@fedos
@fedos 4 жыл бұрын
It will still run. This is a warning that the function and the object are no longer the correct versions to use. They will be removed at some point in the future. So you can use them for now, but the code will cease to function with future versions of the API.
@nestle579
@nestle579 4 жыл бұрын
I ran into the same issue and this is what I came up with: public void UpsertRecord(string table, Guid id, T reccord) { var collection = db.GetCollection(table); var result = collection.ReplaceOne( new BsonDocument("_id", new BsonBinaryData(id, GuidRepresentation.Standard)), reccord, new ReplaceOptions { IsUpsert = true }); }
@stevenkuc
@stevenkuc 3 жыл бұрын
I have same issue var result = collection.ReplaceOne(new BsonDocument("_id", id), record, new UpdateOptions { IsUpsert = true }); Having any update solution?
5 жыл бұрын
Thank you for this tutorial. It has enlightened me. What if there is more then two tables and there are some relations between them? For example a trainings table and an employees and a table that handles for attendees. I think this is for relational databases. Could it even build with mongo db?
@IAmTimCorey
@IAmTimCorey 5 жыл бұрын
Yes it can be built but more likely you would set it up differently. If an employee attends a training session, that training session would be attached to the employee record. No relationship needed.
@FakirCB
@FakirCB 5 жыл бұрын
Or you can do it the normalized way and add a GUID of some record from another collection, just like a foreign key. But then you have to handle fetching related data manually, Mongo won't do that for you. Altough this is a valid method, once the scheme gets more complex, it can very well turn into a huge mess.
@sir.johnbalman9877
@sir.johnbalman9877 3 жыл бұрын
so know this is an old view, but I'm wondering for a structure standpoint it seems that alot of the "child" tables or reference tables that have many to many relations are just consumed by the parent object /document..... is there any case where two document need to be related or do just call the data from document 1 that you need and then add to document 2 for future reads? I hope that was clear but i proable wasn't I contune watching your suggestion app and hope my questions get answered :)
@rachitkohli
@rachitkohli 3 жыл бұрын
Love the way you explain. Good stuff there!
@IAmTimCorey
@IAmTimCorey 3 жыл бұрын
Thanks!
@bjornkreye2211
@bjornkreye2211 4 жыл бұрын
Hi Tim, I have a question to this, how do people hide passwords if they use Atlas for example and the app i avaiable on the internet, people could just refacot it and see the connection string with password. Encryption within the code is also not working since you can just refactor that too. Is there any best practice for that? How do other people safe their data in cloud databases without showing any connectionstring/password in code?
@IAmTimCorey
@IAmTimCorey 4 жыл бұрын
If you are running a web app, the connection string will be securely on the server. If you are running a desktop application, that's a problem that cannot be solved through encryption, etc. as you pointed out. The solution is to go through an API like I do in the TimCo Retail Manager series. More Info: kzbin.info/www/bejne/qHfRlHxvrsuMY6c
@bjornkreye2211
@bjornkreye2211 4 жыл бұрын
@@IAmTimCorey hey thanks for your answer, after I asked I checked pretty much all your Videos. Im half trough the TimCo Retail Manager series Playlist. Thanks for your content, you are doing gods work here ;)
@frozen_dusk579
@frozen_dusk579 4 жыл бұрын
thank you for explaining it so clearly and calmly
@IAmTimCorey
@IAmTimCorey 4 жыл бұрын
Glad it was helpful!
@johnbond6806
@johnbond6806 4 жыл бұрын
I see you use [BsonId] for "tagging" the Id so Bson can notice that it is in fact the id. I tried not using it and still worked so, is it strictly necessary or if I don't use may the data base break at some point?
@IAmTimCorey
@IAmTimCorey 4 жыл бұрын
I believe if you use Id then MongoDB assumes. Tagging it makes it clear.
@kyubi965
@kyubi965 4 жыл бұрын
Hey Tim, really nice tutorial, but im having an issue. I cant run any of the load methods because it gives me this error: FormatException: Cannot deserialize a 'Guid' from BsonType 'ObjectId'. I cant figure out what is causing this, any suggestions?
@IAmTimCorey
@IAmTimCorey 4 жыл бұрын
Did you decorate the ID as a [BsonId]?
@kyubi965
@kyubi965 4 жыл бұрын
@@IAmTimCorey Hey Tim Sorry for the late reply, my last exam was comming up so I have had little time to return to mongo. I did decorate the ID and it did not work, but just recently I updated to VS 2019 and redid the tutorial and now it works. I've got no clue why, I didn't change anything. Thanks for the quick reply and for the tutorial, got hired at a job that use mongo and this really helped get me started. If you need ideas it would be great if you had some time to do a short video on the Builders and Aggregate methods.
@yukiobest6004
@yukiobest6004 5 жыл бұрын
Hi Tim, I am facing an issue while referring to your MongoDb tutorial, which is from 1:01:10 (create NameModel), I have an existing record that contains my Details object (map with DetailsModel class) in my MongoDb. However, when I just wanted to retrieve Id, FirstName and LastName (referred to your NameModel) in my C# program, it also throws System.FormatException as well. Anyhow, your tutorial video still awesome as always!
@IAmTimCorey
@IAmTimCorey 5 жыл бұрын
My guess is that you are trying to map a type (string, int, etc.) to the wrong type in your model (so mapping a GUID to an int property).
@yukiobest6004
@yukiobest6004 5 жыл бұрын
@@IAmTimCorey My Id property in NameModel class is Guid which is same as yours. Lets say i got PrimaryAddress object which is same as your PersonModel. And I have NameModel which I only wanted to retrieve Id, FirstName and LastName. However when I wanted to map into my NameModel, the system throws exception: 'Element 'PrimaryAddress' does not match any field or property of class MongoDbDemo.Program+NameModel.'
@yukiobest6004
@yukiobest6004 5 жыл бұрын
@@IAmTimCorey I have solved by adding [BsonIgnoreExtraElements] :-)
@kherona
@kherona 5 жыл бұрын
@@yukiobest6004 I just had the same issue, glad you found about the [BsonIgnoreExtraElements]. just used it on the class and it worked.
@Phenix25100
@Phenix25100 4 жыл бұрын
@@yukiobest6004 Thank you so much! I also have that issue 😂
@JohnMotamed
@JohnMotamed 4 жыл бұрын
The default value of Guid in C# is not null, it is empty Guid. Now are you saying that MongoDb checks empty Guid for insert and non empty Guid for update? @24:45
@IAmTimCorey
@IAmTimCorey 4 жыл бұрын
Correct. It checks and identifies that it needs a GUID and creates one.
@NAIVEBOYANDY
@NAIVEBOYANDY 4 жыл бұрын
Eye-opening! Thank you, Tim!
@IAmTimCorey
@IAmTimCorey 4 жыл бұрын
You are welcome.
@andreasbrunnstrom8458
@andreasbrunnstrom8458 5 жыл бұрын
I have not gone through the whole video yet but thanks alot. I did not get sql server to install correctly but this works and will get me further along now :)
@IAmTimCorey
@IAmTimCorey 5 жыл бұрын
You are welcome.
@NIKOLAOSGYPAS
@NIKOLAOSGYPAS Жыл бұрын
Hello Tim, the video was great! Do you have a video explaining how to implement a transactions in mongo DB?
@IAmTimCorey
@IAmTimCorey Жыл бұрын
In the Suggestion Site course (playlist here on KZbin), we did transactions when we handled Upvoting suggestions. I don't know the exact video, though.
@Highdad-yt
@Highdad-yt 4 жыл бұрын
LoadRecords with the NameModel gives me an error (Element 'Address' does not match any field or property of class TestMongo)
@IAmTimCorey
@IAmTimCorey 4 жыл бұрын
It sounds like you have a property name mismatch.
@WilqLewiatan
@WilqLewiatan 4 жыл бұрын
Got the same, System.FormatException: „Element 'PrimaryAddress' does not match any field or property of class MongoDB.NameModel.” , But there's no name mismatch?
@kyubi965
@kyubi965 4 жыл бұрын
I had sorta the same thing using the load method on the NameModel rather than the PersonModel. What you can do is, you can decorate your class with [BsonIgnoreExtraElements] public void YourClass{} That will ignore any missing fields in the method.
@ronakpatel6120
@ronakpatel6120 5 жыл бұрын
Awesome video. You really make programming simple.
@IAmTimCorey
@IAmTimCorey 5 жыл бұрын
Thank you!
@SANILJAGTAP-t6l
@SANILJAGTAP-t6l 11 ай бұрын
Hello Tim, Thank you for the great video! I'm getting an error - "Object cannot be cast from DBNULL to other types" while inserting data from from SQL to MongoDB as there are some null values in the sql columns. Can you please help me here? Thanks and Regards, Sanil.
@IAmTimCorey
@IAmTimCorey 11 ай бұрын
It sounds like you might be trying to cast the null into another type. Check which column is having the problem for a given row (test one null at a time) and then look at what you are trying to do with that column. There is probably some type of conversion (even implicit) that you are trying to do to it.
@potelflorent
@potelflorent Жыл бұрын
Hi Tim, thanks for the video, really useful ! I want to log data from a sensor, I wonder if it is better for me to create one document pro session, that contains a list of data that I update everytime I want to add a value, of if I should juste create one collection for one set of measures, and so that every measure + timestamp would be a document. I asked Chat GGT to see, according to it, it would be better to create one document for every single measure (measure + timestamp). Thanks for your help !
@IAmTimCorey
@IAmTimCorey Жыл бұрын
You could make a case for either, but I do think that the most common way to do that would be one document with multiple readings. You are keeping like things together in one object.
@potelflorent
@potelflorent Жыл бұрын
@@IAmTimCorey Thank you for your reply! Indeed it would be easier to get back the values to display them into a chart. My fear was the update function would rewirte the whole List when seeing that the size of the List is different. Anyway, let's try it!
@potelflorent
@potelflorent Жыл бұрын
if someone else want to implement timeseries into mongodb, look at www.mongodb.com/blog/post/building-with-patterns-the-bucket-pattern
@kellysys
@kellysys 5 жыл бұрын
It was very helpful to me. Thank you Tim.
@IAmTimCorey
@IAmTimCorey 5 жыл бұрын
You are welcome.
@dormelamed5974
@dormelamed5974 4 жыл бұрын
Hi Tim :). Great video like always! I have two questions: 1. Every time you do - "var collection = db.GetCollection(table);" - do you bring all the data in the Users collection into the local memory? 2. Is there a better way today to bring data by id (or another field)? all the - "var filter = Builders.Filter.Eq("Id", id);" and then use it like - "collection.Find(filter).First();" looks so clumsy and not elegant... Thanks man!
@IAmTimCorey
@IAmTimCorey 4 жыл бұрын
No, getting the collection is like opening a connection to that set of documents (that "table"). As for a better way, not really. You create the better way by wrapping that in a method.
@danwizedand
@danwizedand 4 жыл бұрын
I noticed that sometimes you use "_id" for the filter and sometimes "Id". I guess that using Id still works because of the BsonId decorator. If that is the case, wouldn't it be safer to always use "_id" to allow the MongoCrud to be generic and always work with whatever model you are mapping?
@IAmTimCorey
@IAmTimCorey 4 жыл бұрын
The problem is that _id doesn't conform to C# naming standards. I try to use Id wherever I can.
@ranavitaln
@ranavitaln 4 жыл бұрын
Hi, in the UpsertRecord Method Do I need to change to ReplaceOptions? I am using net core 3.1
@IAmTimCorey
@IAmTimCorey 4 жыл бұрын
I don't believe so.
@IronTeddyBear
@IronTeddyBear 4 жыл бұрын
@@IAmTimCorey I'm getting a message the UpdateOptions is obsolete, it suggests to use ReplaceOptions instead. I'm using the latest MongoDB.Driver from NuGet, v 2.10.2
@ablgmv
@ablgmv 5 жыл бұрын
Thank you very much! I got one question, didn't get it quite well. As you said exactly the same PrimaryAddress could have another person. What if one of its properties changes? How should we update it for every person?
@IAmTimCorey
@IAmTimCorey 5 жыл бұрын
That's how we would do it. We would load each user and update the value. This happens less often than you would think. If I bought a candy bar for $1 and that record was added to my account, that record would not change. If the candy bar was later sold for $2, that wouldn't affect my record. It is only in the cases where the duplicated values would change across the board that you would have this issue.
@ablgmv
@ablgmv 5 жыл бұрын
@@IAmTimCorey got it, thanks! It looks like MongoDB can be used as a part of CQRS pattern. We have core domain logic that uses SQL and read-only services that uses No-SQL.
@BlackThrax
@BlackThrax 4 жыл бұрын
Hello Tim, Thanks for this great tutorial. I have a question, for Upserting documents, what if I wanted to upsert a list of documents, How can I do it ? Like, Multiple documents at once. Thanks again!
@IAmTimCorey
@IAmTimCorey 4 жыл бұрын
You would use the bulkWrite method to do that: docs.mongodb.com/manual/reference/method/db.collection.bulkWrite/#db.collection.bulkWrite
@BlackThrax
@BlackThrax 4 жыл бұрын
@@IAmTimCorey What is the correct syntax to using UpdateMany() function? I cant seem to get the parameters correctly. My point is, I retrieve a list of objects, I edit them then want to save them again to the database, I dont think using a for loop to send each one of them to the upsert function is an optimal solution.
@ahmetb3286
@ahmetb3286 4 жыл бұрын
That is what i am lookin for. Thx for sharing with us
@IAmTimCorey
@IAmTimCorey 4 жыл бұрын
You're welcome 😊
@deicomic720
@deicomic720 5 жыл бұрын
Got a question on how to do logs using Mongodb. Can you do a tutorial on how to do log with Mongodb?
@IAmTimCorey
@IAmTimCorey 5 жыл бұрын
You can use it like any other database. I'll see what I can do about showcasing that.
@charleswoodruff9013
@charleswoodruff9013 5 жыл бұрын
There's a Nuget for Log4Net using MongoDb, but it hasn't been updated for .Net Core or .Net Standard.
@jeremyperna591
@jeremyperna591 3 жыл бұрын
Do you know if it is possible to design a C# application with MongoDB where all data is stored locally? This would entail programmatically starting an instance of the MongoDB server/driver and connecting to the local database. I know that I can manually start an instance of MongoDB from the terminal with the mongod command, but I haven't seen anyone design an application where the C# application itself starts the MongoDB server, and only locally stored data is served to the application from the local machine's file system.
@TheJessejunior
@TheJessejunior 5 жыл бұрын
Great intro! just cleared my mind!
@IAmTimCorey
@IAmTimCorey 5 жыл бұрын
Excellent!
@codeme8016
@codeme8016 4 жыл бұрын
What a wonderful tutorial!
@IAmTimCorey
@IAmTimCorey 4 жыл бұрын
Thanks!
@Vallecaucanisimo
@Vallecaucanisimo 11 ай бұрын
Hello Tim, First of all, great video, You really got me through some stuff I didn't understand. I am developing a greenfield app and w/ MongoDB precisely because the model is likely to change as the design goes on. The goal is to run my app on different PCs but all pushing and pulling data from a central location running on a local server to keep cost down and control access. Naturally, it would be bad if the db crashes and leaves everyone in the dark. Do you have any insight about periodic backup of the DB? How does one go about doing this? I've had sql dbs get corrupted and that's no fun, so I want to at least implement a backup. Also, say two PCs try to change the same data at the exact same time (unlikely due to the small users size, but plausible). Mongo handles it automatically right? Thanks again!
@IAmTimCorey
@IAmTimCorey 11 ай бұрын
Here is the documentation on backing up your MongoDB instance: www.mongodb.com/docs/manual/tutorial/backup-and-restore-tools/ As for two clients updating the same data at the same time, MongoDB uses a locking mechanism to ensure that updates are placed in order rather than happening at the same time. Now if you were using a multi-write replication system, I'm not sure how that would determine the winner.
@maximecallebaut3949
@maximecallebaut3949 5 жыл бұрын
Thanks just got an assignment of school about mongo
@IAmTimCorey
@IAmTimCorey 5 жыл бұрын
You are welcome.
@asadali118
@asadali118 5 жыл бұрын
Great thanks, a value able content and much appreciated instructions in the end of the video.
@IAmTimCorey
@IAmTimCorey 5 жыл бұрын
You are most welcome. Thanks for watching.
@teemusekki1743
@teemusekki1743 3 жыл бұрын
Should this work in Blazor Server DataLibrary? Or could Blazor be used as interface for MongoDb CRUD in this way?
@theumairtahir1
@theumairtahir1 4 жыл бұрын
Very helpful tutorial to start MongoDB with .Net. Can you please make some more tutorials to discuss more details about it?
@IAmTimCorey
@IAmTimCorey 4 жыл бұрын
I will add it to the list. Thanks for the suggestion.
@sabinsomadas6178
@sabinsomadas6178 4 жыл бұрын
Great video Tim. Mine is a desktop application which will have a local db in the machine, this app can go offline at times. How can I synchronize many such instances of local db to an enterprise db or a cloud db. Any sync frameworks ready for mongodb? Note: the desktop application may go offline for days. Thanks in advance.
@IAmTimCorey
@IAmTimCorey 4 жыл бұрын
When I want to sync a document database, I look at CouchDB/PouchDB. They are designed to sync and have the tools built-in.
@codeme8016
@codeme8016 4 жыл бұрын
Would you have a MongoDb completion course to address its ACID Compliance concerns? I'm an Angular/C# developer who's decided to switch from Firebase to MongoDb. Do you recommend it as the right db choice? Any advice is greatly appreciated.
@IAmTimCorey
@IAmTimCorey 4 жыл бұрын
I don't have a course like that yet, but I probably will at some point. MongoDB is ACID compliant, though, so it is a good choice if you need a NoSQL database.
@codeme8016
@codeme8016 4 жыл бұрын
@@IAmTimCorey Thank you for the prompt response. I am subscribed now to see your wonderful feature videos.
@pabloarthur3045
@pabloarthur3045 4 жыл бұрын
This is the best tutorial I see for SQL Relational programmers to an introduction to a Non-SQL database. I am getting a timeout, I do not see on the tutorial where you tell the C# the connection. Is this automatically? How do I check that?
@IAmTimCorey
@IAmTimCorey 4 жыл бұрын
If you are getting a timeout, it probably means your connection string is incorrect. I would check that and verify all of the details are correct for your machine.
@MonkeyDLuffy-tp3ln
@MonkeyDLuffy-tp3ln 4 жыл бұрын
thank you for this great tutorial i have a problem in the concept, i'm using sql for long time and i don't know really how will i use mongodb with accounting apps or if i even can! can you please make some little project video ?!
@IAmTimCorey
@IAmTimCorey 4 жыл бұрын
Added it to my viewer suggestions list. Thanks
@Lvl9chao
@Lvl9chao 5 жыл бұрын
Hi Tim, do you have a video regarding singleton usage in C#? If I were to build a wpf/winform app that uses mongodb, it would make sense to use a singleton for the MongoCRUD class right? That way I can easily use it across all my winform classes?
@IAmTimCorey
@IAmTimCorey 5 жыл бұрын
The easiest way to utilize a Singleton is to use Dependency Injection. I demo that in a few places, including the TimCo Retail Manager series. In this case, though, I'm not sure that a singleton is the right choice since it stores database information upon instantiation. If you only have one DB then maybe.
@ryanjade2836
@ryanjade2836 3 жыл бұрын
Tim, thank you so much for making this videos. You have made me a better developer. Does MongoDB have an equivalent of a SQL stored procedure?
@IAmTimCorey
@IAmTimCorey 3 жыл бұрын
No, but there isn't a need for one.
@rajnikantsolanki8385
@rajnikantsolanki8385 3 жыл бұрын
It is nice video Tim. Thank you.
@IAmTimCorey
@IAmTimCorey 3 жыл бұрын
You are welcome.
@philmaster92
@philmaster92 4 жыл бұрын
Hey Tim, Excellent video! Say I was trying to do the CRUD operations, but I wanted the properties to be read only and backed by a field. I tried to insert it but it seems the values being put in are uninitialized. How do I make it so mongo realize to get the values from the fields instead of the properties? (I could be misunderstanding the underlying structure of mongo and the attributes but I'm not sure). Thank you.
@IAmTimCorey
@IAmTimCorey 4 жыл бұрын
You need to use the properties in Read/Write mode, not fields.
@rc2893
@rc2893 5 жыл бұрын
Thanks for the information. Really liked the video.
@IAmTimCorey
@IAmTimCorey 5 жыл бұрын
You are welcome.
@hokutoueda6215
@hokutoueda6215 3 жыл бұрын
Excellent Video. Thank you so much. When I try to launch this in Visual Studio, I get the following error in cmd: "The framework 'Microsoft.NETCore.App', version '2.2.0' was not found." Unfortunately 2.2.0 has reached end of life and I only have the option to download version 5. However after doing so I still get an error saying it won't launch because I don't have Version 2.2.0. Could you please let me know what I need to do in order to be able to launch this successfully. Thank you so much!
@wild_elliot
@wild_elliot 3 жыл бұрын
Just a quick question how we going nosql and still going with table?
@IAmTimCorey
@IAmTimCorey 3 жыл бұрын
We aren't using a table. When we work with NoSQL, we conform to the structure it sets up. Basically, we put objects in a collection. That might look like a table, but it isn't.
How to Connect MongoDB to C# the Easy Way
1:10:18
IAmTimCorey
Рет қаралды 75 М.
Connecting C# To MySQL Using Blazor (Full CRUD Actions)
56:06
IAmTimCorey
Рет қаралды 88 М.
Wednesday VS Enid: Who is The Best Mommy? #shorts
0:14
Troom Oki Toki
Рет қаралды 50 МЛН
10 C# Libraries To Save You Time And Energy
33:59
IAmTimCorey
Рет қаралды 209 М.
What is Database Sharding?
9:05
Anton Putra
Рет қаралды 71 М.
Intro to Redis in C# - Caching Made Easy
1:27:29
IAmTimCorey
Рет қаралды 182 М.
MySQL vs MongoDB
5:30
IBM Technology
Рет қаралды 189 М.
Intro To Azure Storage in C#
1:05:37
IAmTimCorey
Рет қаралды 876
I've been using Redis wrong this whole time...
20:53
Dreams of Code
Рет қаралды 379 М.
Simple C# Data Access with Dapper and SQL - Minimal API Project Part 1
1:14:08
migrating mysql to mongodb
25:19
playground
Рет қаралды 18 М.
C# Data Access: Text Files
24:34
IAmTimCorey
Рет қаралды 269 М.