Michael Gabbay
Michael Gabbay

Reputation: 465

how to set mongo local server using Mongo DB Driver .NET

I want to add an option to save data locally in my application using the mongo databse tools, I want to configure all the server information from within my application. I have 2 questions.

  1. the following code is working only after manual setup of mongodb localhost database in this way:

enter image description here

but on A computer that didn't configure the database setting, the code will not work. my code is :

public void createDB()
{
    MongoClient client = new MongoClient();
    var db = client.GetDatabase("TVDB");
    var coll = db.GetCollection<Media>("Movies");
    Media video = new Media("", "");
    video.Name = "split";
    coll.InsertOne(video);
}

this code works only after manual set the database like the picture above. without it I get in the last line A timeout exception. how can I configure it from my application to make it work (define Server) ?

  1. Is the user will be must install MongoDB software on his PC, or the API Package is enough in order to use the database? Many Thanks!

Upvotes: 0

Views: 194

Answers (2)

Navin Chandran
Navin Chandran

Reputation: 51

The Code you are using will search for local mongodb.

Upvotes: 0

CodeCaster
CodeCaster

Reputation: 151594

By using that command you're not "configuring the database", you're running it.

If you don't want to manually run it, but want it to be always running, you should install it as a Windows Service as explained in How to run MongoDB as Windows service?.

You need to install and/or run a MongoDB server in order to use it. Using the API alone is not enough, it's not like SQLite.

Upvotes: 1

Related Questions