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!
@NorbertWebDev5 жыл бұрын
Lol, dident even remake the dislike, there are some bad people runing round the internet :)))
@IAmTimCorey5 жыл бұрын
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. :-)
@23myiah5 жыл бұрын
Yes, very poor show to dislike without even viewing. Thank you Tim for giving us your time and knowledge.
@pylvr80215 жыл бұрын
She must be an Ex lol
@ben.thornhill5 жыл бұрын
Awesome introduction to NoSQL for .NET developers! Thanks as always and best wishes Tim.
@IAmTimCorey5 жыл бұрын
Thank you!
@RalfsBalodis4 жыл бұрын
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
@IAmTimCorey4 жыл бұрын
Thank you!
@Evan-zj5mt5 жыл бұрын
Dude, your videos are great. Neither rushed nor slow, and including all of the salient information a newbie to a subject needs. Kudos!
@IAmTimCorey5 жыл бұрын
Thank you!
@codecomposer883 жыл бұрын
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.
@IAmTimCorey3 жыл бұрын
Glad it was helpful!
@iamtheone9670 Жыл бұрын
Thank you Tim Corey, you explained that mongoDb is faster than sql perfectly. Have learned something new!
@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.
@artemprokhorov5065 жыл бұрын
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.
@IAmTimCorey5 жыл бұрын
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.
@DasturlashniOrganamiz4 жыл бұрын
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 :)
@IAmTimCorey4 жыл бұрын
Awesome! I am glad I was able to be a part of your journey.
@emirhandemirci66774 жыл бұрын
Tim Corey Very useful tutorial. Learned all the basics for a NoSql database in just 1 hour. Keep up the good work!
@IAmTimCorey4 жыл бұрын
Glad it was helpful!
@ohmyohmyohmy25 жыл бұрын
Another terrifically educational video. Thanks for taking the time to produce and post. Always look forward to your content.
@IAmTimCorey5 жыл бұрын
You are welcome.
@xando814 жыл бұрын
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 }); }
@IAmTimCorey4 жыл бұрын
Thanks for sharing.
@shittygamer_jamaican4 жыл бұрын
Thanks a lot.
@steejayk5 жыл бұрын
Your video is NEVER too long!
@IAmTimCorey5 жыл бұрын
Thanks!
@anshulchoure75214 жыл бұрын
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
@IAmTimCorey4 жыл бұрын
Glad it was helpful!
@xeyalteyyubov11752 жыл бұрын
Thanks, Tim that is one of the most beautiful no SQL videos on youtube.
@IAmTimCorey2 жыл бұрын
Thank you!
4 жыл бұрын
Thanks Tim. Very nice introduction to MongoDB and NoSQL world.
@IAmTimCorey4 жыл бұрын
Glad it was helpful!
@austinmudadi91789 күн бұрын
Impressive, thanks Tim. Always the best!
@IAmTimCorey8 күн бұрын
You are welcome.
@shrimpsnplants5 жыл бұрын
"That's the basic structure of MongoDB meaning that isn't really a structure" you made my day :D
@IAmTimCorey5 жыл бұрын
I'm glad you enjoyed it.
@AnalogDave4 жыл бұрын
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.
@IAmTimCorey4 жыл бұрын
Glad it was helpful!
@mirragemelkyr4 жыл бұрын
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.
@IAmTimCorey4 жыл бұрын
Glad it was helpful!
@anton_zhernosek2 жыл бұрын
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
@IAmTimCorey2 жыл бұрын
I am glad you find them valuable.
@xando814 жыл бұрын
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; } }
@IAmTimCorey4 жыл бұрын
Thanks for sharing.
@alexcyoung5 жыл бұрын
Great video Tim! And a nice, simple way of handling CRUD operations without requiring models to inherit from a common 'entity' base class.
@IAmTimCorey5 жыл бұрын
Thanks. I considered a common model base but decided against it for this video.
@FakirCB5 жыл бұрын
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();
@IAmTimCorey5 жыл бұрын
Awesome! Thanks for sharing.
@taha58714 жыл бұрын
Awesome video explaining how u use MongoDB with C# , thanks so much 💙💙
@IAmTimCorey4 жыл бұрын
You're very welcome!
@Randomness-rl8lv3 жыл бұрын
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-iamtimcorey75973 жыл бұрын
We appreciate the suggestion and I have added it to Tim's list.
@CaatjuhNL14 жыл бұрын
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!
@IAmTimCorey4 жыл бұрын
You're very welcome!
@alvinbernardo95514 жыл бұрын
For all free tutorial in youtube, this is great
@IAmTimCorey4 жыл бұрын
Thank you!
@georgetuccio60535 жыл бұрын
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.
@IAmTimCorey4 жыл бұрын
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.
@amirday2daychallenge5 жыл бұрын
Tq for your short and sweet video about how to use MongoDB in C#, it was handy.
@IAmTimCorey5 жыл бұрын
You are most welcome. Thanks for watching.
@amoljawalkar62732 жыл бұрын
One of the best tutorial found online. Thank you so much
@tomthelestaff-iamtimcorey75972 жыл бұрын
Your endorsement is much appreciated! Thank you for helping to spread the word.
@umairraza1923 жыл бұрын
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 .
@IAmTimCorey3 жыл бұрын
You're very welcome!
@Dumah794 ай бұрын
Your explations are best Tim just thank you.
@IAmTimCorey4 ай бұрын
You are welcome.
@pampula93275 жыл бұрын
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.
@IAmTimCorey5 жыл бұрын
I'm glad it was so easy to follow. I'll add your suggestion to the list.
@toshitosliba47372 жыл бұрын
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.d5 жыл бұрын
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.
@IAmTimCorey5 жыл бұрын
Excellent. Let us know how it goes.
@Diploidus4 жыл бұрын
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]?
@IAmTimCorey4 жыл бұрын
Yep, that will work.
@codecomposer883 жыл бұрын
Thank you! Just what I was looking for.
@AhmetYigiter5 жыл бұрын
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...
@IAmTimCorey5 жыл бұрын
Awesome!
@Randomness-rl8lv4 жыл бұрын
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!!
@IAmTimCorey4 жыл бұрын
I will add it to the list. Thanks for the suggestion.
@zbigniewcwiakalski72537 ай бұрын
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 ?
@Tiagorockman3 жыл бұрын
Top one best video i have seen about mongodb c#. Thanks alot for share!
@tomthelestaff-iamtimcorey75973 жыл бұрын
His goal is to make learning easier. It appears he is doing just that!
@khemo2405 жыл бұрын
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 😅
@IAmTimCorey5 жыл бұрын
Excellent!
@T-par-T4 жыл бұрын
Mark my words: Tim is the best!
@IAmTimCorey4 жыл бұрын
Thanks!
@codecomposer883 жыл бұрын
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?
@IAmTimCorey3 жыл бұрын
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.
@codecomposer883 жыл бұрын
@@IAmTimCorey Thank you!
@rongliao92554 жыл бұрын
Great tutorial! NoSQL database can be a great choice for the new projects!
@IAmTimCorey4 жыл бұрын
Thanks!
@cbirchy874 жыл бұрын
Hi Tim, It appears the ReplaceOne has been made obsolete. What the is new way of doing the same thing for an Upsert?
@nestle5794 жыл бұрын
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 }); }
@jakubondrak19225 жыл бұрын
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
@IAmTimCorey5 жыл бұрын
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.
@KouroushMetal5 жыл бұрын
Very Good One. Thanks. Big questions are Group, Index, Search Speed On non-Id columns, and datagridview datasource with all these not consistent documents.
@IAmTimCorey5 жыл бұрын
Thanks for the suggestions.
@cameronroberson56274 жыл бұрын
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,
@IAmTimCorey4 жыл бұрын
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.
@cameronroberson56274 жыл бұрын
@@IAmTimCorey Great answer. Thanks Tim
@mrfreddie04p5 жыл бұрын
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.
@IAmTimCorey5 жыл бұрын
That's interesting. Not sure why you had that error.
@Tajdev3 жыл бұрын
Great Video. Please do advance Level video also which covers Aggregation, ACID AND Triggers.
@tomthelestaff-iamtimcorey75973 жыл бұрын
We appreciate the suggestion and I have added it to Tim's list.
@DamianWalczak4 жыл бұрын
Thank you Tim that was very informative
@IAmTimCorey4 жыл бұрын
You are welcome.
@HelmutPolischer3 жыл бұрын
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 }); }
@IAmTimCorey3 жыл бұрын
Thanks for sharing.
@touseef.awan14 жыл бұрын
Thank you Tim. You are best.
@IAmTimCorey4 жыл бұрын
You are very welcome
@sepwille77934 жыл бұрын
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?
@IAmTimCorey4 жыл бұрын
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.
@johnbond68064 жыл бұрын
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?
@jaspercoleman32693 жыл бұрын
Great video content as always. Thanks for sharing the knowledge, it keeps me motivated to learn more.
@IAmTimCorey3 жыл бұрын
You are welcome.
@summerbreeze25syria4 жыл бұрын
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?
@IAmTimCorey4 жыл бұрын
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_orphan4 жыл бұрын
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!
@fedos4 жыл бұрын
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.
@nestle5794 жыл бұрын
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 }); }
@stevenkuc3 жыл бұрын
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?
@IAmTimCorey5 жыл бұрын
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.
@FakirCB5 жыл бұрын
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.johnbalman98773 жыл бұрын
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 :)
@rachitkohli3 жыл бұрын
Love the way you explain. Good stuff there!
@IAmTimCorey3 жыл бұрын
Thanks!
@bjornkreye22114 жыл бұрын
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?
@IAmTimCorey4 жыл бұрын
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
@bjornkreye22114 жыл бұрын
@@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_dusk5794 жыл бұрын
thank you for explaining it so clearly and calmly
@IAmTimCorey4 жыл бұрын
Glad it was helpful!
@johnbond68064 жыл бұрын
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?
@IAmTimCorey4 жыл бұрын
I believe if you use Id then MongoDB assumes. Tagging it makes it clear.
@kyubi9654 жыл бұрын
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?
@IAmTimCorey4 жыл бұрын
Did you decorate the ID as a [BsonId]?
@kyubi9654 жыл бұрын
@@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.
@yukiobest60045 жыл бұрын
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!
@IAmTimCorey5 жыл бұрын
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).
@yukiobest60045 жыл бұрын
@@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.'
@yukiobest60045 жыл бұрын
@@IAmTimCorey I have solved by adding [BsonIgnoreExtraElements] :-)
@kherona5 жыл бұрын
@@yukiobest6004 I just had the same issue, glad you found about the [BsonIgnoreExtraElements]. just used it on the class and it worked.
@Phenix251004 жыл бұрын
@@yukiobest6004 Thank you so much! I also have that issue 😂
@JohnMotamed4 жыл бұрын
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
@IAmTimCorey4 жыл бұрын
Correct. It checks and identifies that it needs a GUID and creates one.
@NAIVEBOYANDY4 жыл бұрын
Eye-opening! Thank you, Tim!
@IAmTimCorey4 жыл бұрын
You are welcome.
@andreasbrunnstrom84585 жыл бұрын
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 :)
@IAmTimCorey5 жыл бұрын
You are welcome.
@NIKOLAOSGYPAS Жыл бұрын
Hello Tim, the video was great! Do you have a video explaining how to implement a transactions in mongo DB?
@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-yt4 жыл бұрын
LoadRecords with the NameModel gives me an error (Element 'Address' does not match any field or property of class TestMongo)
@IAmTimCorey4 жыл бұрын
It sounds like you have a property name mismatch.
@WilqLewiatan4 жыл бұрын
Got the same, System.FormatException: „Element 'PrimaryAddress' does not match any field or property of class MongoDB.NameModel.” , But there's no name mismatch?
@kyubi9654 жыл бұрын
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.
@ronakpatel61205 жыл бұрын
Awesome video. You really make programming simple.
@IAmTimCorey5 жыл бұрын
Thank you!
@SANILJAGTAP-t6l11 ай бұрын
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.
@IAmTimCorey11 ай бұрын
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 Жыл бұрын
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 Жыл бұрын
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 Жыл бұрын
@@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 Жыл бұрын
if someone else want to implement timeseries into mongodb, look at www.mongodb.com/blog/post/building-with-patterns-the-bucket-pattern
@kellysys5 жыл бұрын
It was very helpful to me. Thank you Tim.
@IAmTimCorey5 жыл бұрын
You are welcome.
@dormelamed59744 жыл бұрын
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!
@IAmTimCorey4 жыл бұрын
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.
@danwizedand4 жыл бұрын
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?
@IAmTimCorey4 жыл бұрын
The problem is that _id doesn't conform to C# naming standards. I try to use Id wherever I can.
@ranavitaln4 жыл бұрын
Hi, in the UpsertRecord Method Do I need to change to ReplaceOptions? I am using net core 3.1
@IAmTimCorey4 жыл бұрын
I don't believe so.
@IronTeddyBear4 жыл бұрын
@@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
@ablgmv5 жыл бұрын
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?
@IAmTimCorey5 жыл бұрын
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.
@ablgmv5 жыл бұрын
@@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.
@BlackThrax4 жыл бұрын
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!
@IAmTimCorey4 жыл бұрын
You would use the bulkWrite method to do that: docs.mongodb.com/manual/reference/method/db.collection.bulkWrite/#db.collection.bulkWrite
@BlackThrax4 жыл бұрын
@@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.
@ahmetb32864 жыл бұрын
That is what i am lookin for. Thx for sharing with us
@IAmTimCorey4 жыл бұрын
You're welcome 😊
@deicomic7205 жыл бұрын
Got a question on how to do logs using Mongodb. Can you do a tutorial on how to do log with Mongodb?
@IAmTimCorey5 жыл бұрын
You can use it like any other database. I'll see what I can do about showcasing that.
@charleswoodruff90135 жыл бұрын
There's a Nuget for Log4Net using MongoDb, but it hasn't been updated for .Net Core or .Net Standard.
@jeremyperna5913 жыл бұрын
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.
@TheJessejunior5 жыл бұрын
Great intro! just cleared my mind!
@IAmTimCorey5 жыл бұрын
Excellent!
@codeme80164 жыл бұрын
What a wonderful tutorial!
@IAmTimCorey4 жыл бұрын
Thanks!
@Vallecaucanisimo11 ай бұрын
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!
@IAmTimCorey11 ай бұрын
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.
@maximecallebaut39495 жыл бұрын
Thanks just got an assignment of school about mongo
@IAmTimCorey5 жыл бұрын
You are welcome.
@asadali1185 жыл бұрын
Great thanks, a value able content and much appreciated instructions in the end of the video.
@IAmTimCorey5 жыл бұрын
You are most welcome. Thanks for watching.
@teemusekki17433 жыл бұрын
Should this work in Blazor Server DataLibrary? Or could Blazor be used as interface for MongoDb CRUD in this way?
@theumairtahir14 жыл бұрын
Very helpful tutorial to start MongoDB with .Net. Can you please make some more tutorials to discuss more details about it?
@IAmTimCorey4 жыл бұрын
I will add it to the list. Thanks for the suggestion.
@sabinsomadas61784 жыл бұрын
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.
@IAmTimCorey4 жыл бұрын
When I want to sync a document database, I look at CouchDB/PouchDB. They are designed to sync and have the tools built-in.
@codeme80164 жыл бұрын
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.
@IAmTimCorey4 жыл бұрын
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.
@codeme80164 жыл бұрын
@@IAmTimCorey Thank you for the prompt response. I am subscribed now to see your wonderful feature videos.
@pabloarthur30454 жыл бұрын
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?
@IAmTimCorey4 жыл бұрын
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-tp3ln4 жыл бұрын
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 ?!
@IAmTimCorey4 жыл бұрын
Added it to my viewer suggestions list. Thanks
@Lvl9chao5 жыл бұрын
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?
@IAmTimCorey5 жыл бұрын
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.
@ryanjade28363 жыл бұрын
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?
@IAmTimCorey3 жыл бұрын
No, but there isn't a need for one.
@rajnikantsolanki83853 жыл бұрын
It is nice video Tim. Thank you.
@IAmTimCorey3 жыл бұрын
You are welcome.
@philmaster924 жыл бұрын
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.
@IAmTimCorey4 жыл бұрын
You need to use the properties in Read/Write mode, not fields.
@rc28935 жыл бұрын
Thanks for the information. Really liked the video.
@IAmTimCorey5 жыл бұрын
You are welcome.
@hokutoueda62153 жыл бұрын
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_elliot3 жыл бұрын
Just a quick question how we going nosql and still going with table?
@IAmTimCorey3 жыл бұрын
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.