I have setup mongodb 64bits on Windows. I ran server and client successfully.
But when I type:
show dbs
Output is
local 0.000GB
Why ? show dbs is supposed to list all databases at least the default one "test"
am I wrong ?
Although you may be in the test database by default, the database does not actually get created until you insert a document into a collection in the database which will implicitly create the collection and the database.
Related
This question already has an answer here:
Mongo: show dbs doesn't show the test db. Why?
(1 answer)
Closed 3 years ago.
I tried going into a mongo shell and creating a DB, and it seems to have worked, its saying I'm in the db i created but when I run show databases; it doesnt show in the list.
Here is what terminal shows:
> show databases;
admin 0.000GB
config 0.000GB
local 0.000GB
> use sr-dev
switched to db sr-dev
> show databases;
admin 0.000GB
config 0.000GB
local 0.000GB
> db
sr-dev
>
Mongo only creates databases and collections as needed, as lazily as possible. You didn't "create" sr-dev, you're merely "using" it at the moment. Think of it as "being in the namespace sr-dev". Once you insert your first data the actual database will be created. Before you do that, there's no need for it to exist.
Create a Database
If a database does not exist, MongoDB creates the database when you first store data for that database. As such, you can switch to a non-existent database and perform the following operation in the mongo shell: [..]
https://docs.mongodb.com/manual/core/databases-and-collections/#create-a-database
When you create a database in MongoDb shell, it won't show up until there are some collections in your database.
Please try adding some collections in your newly created database and run show databases command again, It will show up.
db.createCollection('collection_name',{...})
Here the 2nd parameter is optional.
Please read MongoDb createCollection documentation for more info, on 2nd parameter options.
You will have to create collection inside your db.
MongoDB works this way.
I am a newbie to MongoDB.
I use mongodb db.copyDatabase command for copying database to another server.
After I copy(I got the Ok sign from mongo shell), I found something strange.
In my source Server db
> show dbs
newstrust 13.947GB
In my Target Server db
> show dbs
ntrust1 2.188GB
I checked my db and compare source server db and target server db. The number of collections and rows are same.
I am not able to understand the problem
Please see below my query, I ran [show dbs] on mongos/router server and gives me
different result than running the same command on Replica Set server:
As you can see below, some databases such as [clients] is in RS server but it is not in Mongos server, and vise-versa.. also some similar databases are different in size.. Why ?
I am migrating these databases to AWS, I am confused as to which database(s) I need to migrate ? and what about the size of some of these databases - for instance the DB [ device1 ] is 0.156GB when it is listed from RS server, but it is 0.078GB when it is listed from RS server..
This is actually a production system and I am concerned if something is not right. Where should I check to get accurate information about the database I am migrating to AWS ? and how do I know which DB that is being used and the DB that is not used..
I am an Oracle DBA, I am new to Mongo, I'd appreciate all the advice & suggestions you can provide to get a clear picture about these databases before I can start the migration process. It would also be helpful if I can find a detailed instructions as to how to migrate Replica Sets DBs to a new hardware such as AWS..
**>> From MongoS**
mongos> show dbs
admin (empty)
config 0.063GB
dev-mgt 0.453GB
device1 0.156GB
rtime 0.203GB
zales 83.767GB
site 0.953GB
eedb (empty)
test (empty)
**From RS server**
rs0:PRIMARY> show dbs
admin (empty)
config (empty)
Device1 0.078GB
clients 86.036GB
rtime 0.203GB
zales 83.767GB
test (empty)
Please advice. Thank you !
Not all your collections are sharded. If you have a collection that isn't sharded, and you look for it on your secondary shard, you won't find it. Non-sharded collections will only go to a single replica set. You should always go through your mongos instance to browse your dbs and data.
From documentation:
Primary Shard
Every database has a “primary” 1 shard that holds all the un-sharded
collections in that database.
I apologize if this is easily google-able or already asked before.
I have tried googling, but I get hits to explain how to get all collections.
I am using MongoDB 2.4.8
Run show databases or show dbs in the Mongo shell:
$ mongo
MongoDB shell version: 2.4.8
connecting to: test
> show databases
db1 0.203125GB
local 0.078125GB
test 0.203125GB
This will list your databases.
To list the available databases, use the helper show dbs. See also How can I access different databases temporarily? to access a different database from the current database without switching your current database context (i.e. db..) source
I'm a beginner with MongoDB and I've some questions:
When I'm connected to Mongo, and i execute show dbs I see 2 databases: admin and local. What's their role? Then if I execute an insert command like db.foo.insert({"value":"mongo"}), the test database appears. Why? How can i specify a custom name for a database?
With show dbs I get the databases (somehow like show databases in sql), how can I then list the collections inside a database (I would use show tables in sql)?
When executing a command, the MongoDB tutorial always uses the db object. Is it the main object (a sort of "connection" object) that has to used for executing commands or it's something else?
Thanks!
admin and local contain various settings local to the server, like users who are authenticated to connect. Under beginner usage, you shouldn't need to worry about them at all. By default you connect to a database named test. To connect to a new database, just use databasename from the mongo command line, or mongo databasename from your OS shell.
use [database_name] and then show collections
The db object is your root handle to the currently-selected database on the mongo commmand line. The command line is really just a Javascript command line, and there are various mongodb-specific objects and functions exposed that let you do stuff. Try help() for a full listing.