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
Post a Comment