Why is there a database named "test" when connecting MongoDB using Studio3T? - mongodb

I'm learning MongoDB and trying to use Atlas. I created a remote cluster and tried to connect it using both MongoDB Compass and Studio 3T. However, I noticed that after connecting with Studio 3T, there was an empty database named "test" appearing in the left panel, below "admin" and "local" databases. Where did it come from? And how can I drop it? Because when I tried to drop this database, I got this error
Mongo Server error (MongoCommandException): Command failed with error 8000 (AtlasError): 'user is not allowed to do action [dropDatabase] on [test.]' on server ac-bkmhuxm-shard-00-02.w2nutv2.mongodb.net:27017.
The full response is:
{
"ok" : 0.0,
"errmsg" : "user is not allowed to do action [dropDatabase] on [test.]",
"code" : 8000.0,
"codeName" : "AtlasError"
}
After changing the roles in Atlas, I can now delete the database. However it keeps appearing when I make a new connection to MongoDB. Why is that?

Database test is the default database when you don't define anything.
Databases local, admin and config are MongoDB system internal databases, you should not touch them unless advised by MongoDB support or special admin tasks.
See also 3 default database in MongoDB

Related

Error while connecting MongoDB ATLAS TO MONGO DB COMPASS

I am a beginer in mongoDB and learning Mongodb atlas.
In MongoDB Atlas, Under database access created username and password ( password is system generated and has no special character)
Under Network access added a public ip address (allow access from anywhere)
Under database deployment loaded sample database.
Now I wanted to see my cluster data, so wanted to connect it to vs code or MongoDB Compass. I clicked connect, selected connect using mongo db compass, copied the string.
now i opened Mongodb compass, and under New connection i.e connect to a MongoDB deployment, i entered my URL
mongodb+srv://gourav_singh:7gamf8UkL8B6MET#cluster0.9dmds.mongodb.net/test
clicked Connect
But i got error as : Unable to connect: connect ECONNREFUSED 3.6.85.199:27017
How I can fix it, Looking for kind help. Thanks in advance

Mongodb Charts connect to Mongo but doesn`t find all databases

I've brought up the mongodb-charts in my desktop and connected it to my mongodb database. When I connect to the database through mongodb-charts I see all of my databases there except the one named "admin" which is the one I need and where my data is. Why is this happening? I am using the same user to connect studio 3T to my mongodb that I use to connect mongodb-charts to mongodb. The picture below shows that I have the database "admin" in mongodb when I connect through studio 3T, but can't see it when connecting by mongodb-charts to mongodb...
MongoDB Charts currently excludes databases which are considered internal:
admin: stores user & role information
config: stores sharded cluster and session metadata
local: stores local node data including the replication oplog
It is generally not recommend to use any of these databases for your own application data, however the MongoDB server (as at 4.2) does not prevent you from doing so.
If you have chosen to store application data in the admin database you will have to copy it to a new database in order to visualise in MongoDB Charts.

Error 13 when trying to authenticate to MongoDB

I'm trying to connect to MongoDB through JDBC. The connection string is like below,
mongodb://localhost:27017/games?authSource=admin
However I'm getting the following trace:
{ "ok" : 0.0, "errmsg" : "not authorized on admin to execute command { listDatabases: 1 }", "code" : 13 }
My intention is not listing all the databases, but the user has to authenticate against admin database and can read/write on games database. What mistake I'm making here?
I want user X to authenticate against admin DB but read just games DB so not sure why it asks for listDatabase privilege.
First, I assume you are using the MongoDB Java Driver, which is actually not JDBC.
It would be helpful for you to share:
How you created your user
The Java code that you are executing
The version of mongo-java-driver and MongoDB that you are using
But based on the error, it appears that you are successfully authenticating. I strongly suspect that you are either directly calling listDatabases() or listDatabaseNames().
The other thing that does not look quite right is the fact that you are specifying authSource=admin in your MongoClientURI. But that issue should have given you an Autentication Failed error. You should be either leaving the authSource off of the connection string or specify authSource=games.
Based on what you described, when you created your user, you should have created the user in the games database (users will actually be stored in the admin database, but you would be authenticating against the games database).

MongoDB: how do I authenticate when executing the `copydb` command

I have a replica set on a remote host which requires authentication in order to connect. The original (root) user was created in the admin database which I have used in order to remotely connect. I building some sort of a "backup" script which copies a db into the replica set and in a later time I should be able to copy a db from the remote location into other MongoDB instances.
So I wrote the script to copy a database by connecting TO the remote location, authenticating and then running the db.runCommand using copydb: 1. It works great, no problems here.
When I try to copy a db back into my local machine that's when things go wrong, mainly because I have to authenticate as part of the copydb command. I originally tried to use the same technique (db.runCommand) but since the nonce and key authentication are messy by themselves I tried to solve the problem first by writing the commands manually into mongo's shell using db.copyDatabase, according to the documentation it should do this process for me.
This is the command:
db.copyDatabase('from_db', 'to_db', 'remote.host.example.com', 'my_user', 'my_password')
Which responds with:
{ "ok" : 0, "errmsg" : "Authentication failed.", "code" : 18 }
I tried switching roles (root, userAdmin, readWrite, ...) but nothing works. I tried creating another user inside the db I am trying to copy, but that didn't seems to do much other than change the response a little into:
{
"ok" : 0,
"errmsg" : "unable to login { ok: 0.0, code: 18, errmsg: \"Authentication failed.\" }"
}
I searched everywhere, went over anything in the manual which seemed remotely relevant and I still can't figure it out.
How am I suppose to copy a db from a remote location which requires an authentication??

Unable to connect to mongohq at heroku using shell

I installed mongohq:sandbox at Heroku. When I want to connect to mongo, it occurs an error:
mongo linus.mongohq.com:10123/app10575123 -u my_user -p pwd123
MongoDB shell version: 2.2.2
connecting to: linus.mongohq.com:10123/app10575123
> show dbs
Wed Jan 9 06:00:50 uncaught exception: listDatabases failed:{ "errmsg" : "need to login", "ok" : 0 }
Login and password are correct.
You are connected to the database, but for the shared database plans at MongoHQ (especially the sandbox ones), for security reasons, they do not include admin-level access to the Mongo instance ... only access to your actual database.
"show dbs" is an admin-level command and, in this case, would show other databases on that sandbox MongoDB process.
Instead, you will want to use commands like:
show collections
db.[collection_name].findOne()
db.stats()
db.[collection_name].stats()
db.[collection_name].ensureIndex({foo:1, bar:1}, {background:true})
... and so on.
I hope this helps!
You should be able to show collections, but show dbs requires admin privileges.