Karnivaurus
Karnivaurus

Reputation: 24161

MongoDB: Connecting to database

I have installed MongoDB and I am successfully running it as a Windows Service, which I have called MongoDB. I am able to add data to the database through my ASP.NET MVC application, as expected. In the MongoDB configuration file, the path for my data is set to the default C:\data\db.

My question is: how can I now connect to this database from the command line? I want to be able to do things like delete the database or query it, and I want to do this from Windows command prompt. I am aware that running mongo.exe allows such functionality, but what arguments to I supply when I run it? I don't seem to ever recall giving a name to my database, other than naming the Windows Service...

Thanks :)

Upvotes: 0

Views: 401

Answers (2)

Ben Gamble
Ben Gamble

Reputation: 411

MongoDB is designed to create databases on demand when you put data in them. local is not a default; it holds internal state information like replication status. You don't put your data there, and you definitely don't rename or delete it. When interacting with a database using the mongo shell, you generally specify the db with use dbname; when using the C driver, you generally specify the dbname in calls to driver routines that return mongoc_database_t or mongoc_collection_t structs.

Upvotes: 1

yaoxing
yaoxing

Reputation: 4203

One thing I love most about MongoDB is: you can almost find everything from MongoDB Manual
So there are two ways to specify database name:

mongo localhost/dbname

or you can connect to db first:

mongo // defaults to localhost/test

And then specify db name by

show dbs  // show all dbs
use dbName

You can almost do everything in mongo shell. Please read the Manual.

Upvotes: 0

Related Questions