Inserting multiple data into MongoDB using c# -


i started use mongodb , wanted ask how put multiple data 1 variable. want user registration windows forms. whenever check on internet see people creating multiple variables each data. example while can:

insert users (username, password) values ('{user}', '{pass}'); 

execute code on mysql on mongodb need create variables every user registered. means not automatic.

you've not mentioned driver using assume you're using official .net driver.

to insert multiple documents mongodb use insertmanyasync method. example shown in official mongodb c# driver documentation.

an example method is:

public task insertusers(ienumerable<user> users) {   // create client   const string connectionstring = "mongodb://localhost:27017";         var client = new mongoclient(connectionstring);    // database   var database = client.getdatabase("mydb");    // user collection   var collection = _database.getcollection<user>("users");    // insert users , return async task   return collection.insertmanyasync(users); } 

but whenever check on internet see people creating multiple variables each data.

i recommend reading on difference between relational database (like mysql) , document db (like mongodb) as, while both store data, quite different technologies , different problems.


Comments

Popular posts from this blog

networking - Vagrant-provisioned VirtualBox VM is not reachable from Ubuntu host -

c# - ASP.NET Core - There is already an object named 'AspNetRoles' in the database -

ruby on rails - ArgumentError: Missing host to link to! Please provide the :host parameter, set default_url_options[:host], or set :only_path to true -