Thanks for Tutorial first of all, your video is really good for beginners. For 6:14 -> I think with C# 8 there is null! equalization referance for properties, which is much better for best practice. If you mark prop as nullable with " ? " operator, it may cause leak problems beacuse it makes you able pass null for that prop. Otherwise " null! " referance makes prop " nullable but cannot be null " . And I think for this example " CategoryName " property is one of MUST HAVE props. That means we should give it a name which means cannot pass it null in any scenario. Correct me if I'm wrong please. :)
Sorry,I haven't heard about null!. I never understood why they have adde ? In a string property. It wasn't alwys like this. We always put the [required] validation in a model property. So there wont be a problem of null value insertion to database.
just allocate ImongoCollection and BsonDocument, then you can add to your database directly, here's my simple code: MongoClient client = new MongoClient(connectionString); IMongoDatabase database = client.GetDatabase(databaseName); // Get a reference to the collection IMongoCollection collection = database.GetCollection("products"); // Create a new document BsonDocument newProduct = new BsonDocument { { "Name", "Sample Product" }, { "Price", 19.99 }, { "Category", "Electronics" } }; // Insert the document collection.InsertOne(newProduct); Console.WriteLine("Document inserted."); Check out IMongoCollection class for other methods to add to database
Isn’t the mongodb client supposed to be a singleton and not transient
Yes.. mongo db client should be singleton according Microsoft docs.
Sorry about that.
Password already in connection string you have to get it from MongoDb network users page and paste it
Thanks for Tutorial first of all, your video is really good for beginners.
For 6:14 -> I think with C# 8 there is null! equalization referance for properties, which is much better for best practice. If you mark prop as nullable with " ? " operator, it may cause leak problems beacuse it makes you able pass null for that prop. Otherwise " null! " referance makes prop " nullable but cannot be null " . And I think for this example " CategoryName " property is one of MUST HAVE props. That means we should give it a name which means cannot pass it null in any scenario. Correct me if I'm wrong please. :)
Sorry,I haven't heard about null!. I never understood why they have adde ? In a string property. It wasn't alwys like this.
We always put the [required] validation in a model property. So there wont be a problem of null value insertion to database.
great video, VERY informative! thank you!
your videos are so helpful. Please create a project video using MudBlazor and MongoDB
How to authenticate Connection Strings of mongoDB like we do for MySQL or SqlServer by using UserId and Password?
bro you have predefined schema but in my case I have random data I want to store in mongodb any suggestions?
just allocate ImongoCollection and BsonDocument, then you can add to your database directly, here's my simple code:
MongoClient client = new MongoClient(connectionString);
IMongoDatabase database = client.GetDatabase(databaseName);
// Get a reference to the collection
IMongoCollection collection = database.GetCollection("products");
// Create a new document
BsonDocument newProduct = new BsonDocument
{
{ "Name", "Sample Product" },
{ "Price", 19.99 },
{ "Category", "Electronics" }
};
// Insert the document
collection.InsertOne(newProduct);
Console.WriteLine("Document inserted.");
Check out IMongoCollection class for other methods to add to database
How to upload images using dotnet core api sql server
You can follow this, ua-cam.com/video/bFbCAJCxxHI/v-deo.html
at 33:11 minutes you didn't create a mongodb Database. how did u insert it ?. @ravindradevarani
It will be created automatically, if you provide correct connection string and every setting related to it.