Mongodb not listing collections when connecting remotely from CentOS - mongodb

Mongo server: Windows 10 (host)
client: CentOS 6.2, a virtual box vm on windows 10 host. This is actually a cloudera quick start vm.
Issue:
mongodb connects to the remote server (from CentOS to Windows) via terminal, lists the databases fine, but 'show collections' just returns blank. That said, the collections are accessible because I can query any collection and the count also gives me the correct results.
On the other hand, I have connected to the same mongo server from IntelliJ and it shows all the collections just fine.
Just curious as to why this is happening.. Any comments?
Side Note: is there a mongodb command to count the number of collections in a database?
Thanks
_Vamsi

Make sure you are using the database you want to show the collections for. You may be using a database that doesn't have any collections.
> use desiredDatabase
> show collections
If the list is still empty, try signing in with an admin user account. The user needs to be able to perform the listCollections action. The dbAdmin role includes the listCollections action.
To get the count you can use the getCollectionNames function which returns an array and you can get the length from that.
> db.getCollectionNames().length

Related

MongoDB. Studio3T. Mongoose. Hyper returns empty array. Pluralization in naming most likely not the issue

I ran mongod in Hyper Terminal.
I established connection with Studio3T and MongoDB. And created collection and documents in Studio3T. The database, collection, and documents appear in Studio3T and MongoDB. In Hyper the database and collection exist, but the documents are not there. Any idea why?
I have consulted stackoverflow and could not find the answer in the resources listed (sorry if I missed something):
Mongoose always returning an empty array NodeJS
Model.find() returns empty in mongoose
Mongoose always return empty array?
What are naming conventions for MongoDB?
MongoDB:
Mongosh in Hyper:
Studio3T:
Code in Atom:
Run code and result in Hyper:
I started mongod and connected to the MongoDB server locally. My application code pointed to the following:
mongoose.connect("mongodb://localhost:27017/wikiDB");
The above is local. But my data is on the cloud-based MongoDB Atlas Cluster. I shouldn't need to run mongod. So, I changed my application code:
mongoose.connect("mongodb+srv://admin-yourname:password#blahblahblah.mongodb.net/wikiDB");
where yourname AND password AND blahblahblah are specific to the coder.
Now my application code points to the Atlas Cluster where my data is.
Summary:
My data is on the cloud-based Atlas Cluster.
To see my data on the Atlas Cluster from the command line, I "Connect with the MongoDB Shell" and run the connection string that MongoDB provides in the command line. Now I see my data in the command line.
To see my data on the Atlas Cluster when I run my code, I use "Connect your application" and place the connection string that MongoDB provides in my code (the mongoose.connect(....) ). Now when I run my code, I can see my data in my browser or command line if I console.log it.
If you are in the command line and run mongod in one tab, and mongosh in another, and use db.articles.find(), then nothing will appear but an empty array. That's because the data is on the cloud-based Atlas cluster. In this instance, you are viewing things locally.
If your application code points to your local MongoDB server (ran mongod in one tab, mongosh in another), then when you run the code you will see nothing but an empty array because the data is on the cloud-based Atlas cluster. In this instance, you are viewing things locally.

Connect to Database directly via Mongo Compass

Via shell, I can directly connect to mongo database with this string
mongo --ssl host1,host2:port/MyDataBase...
And I land directly on the MyDataBase.
Is there a similar way to do it in Compass? I get connected to whole server and I can see all the other databases. I just want to connect to MyDataBase.
I am using the lattest version of Compass, so it may differ from your current version.
It is important the you are in the network of the server, or use a VPN connection, otherwise, it does not work.
Step 1
Step 2
Please,let me know if that works!

Robo3T Does not show the database

I can connect to a MongoDB Atlas replica set but it has no database.
When I click the master node, it shows a new shell
And I can find the objects with db.getCollection('aCollection').find()
How can I show/add the database in the left pane?
ps. I was using Robo3T 1.3.1
IMO this is a issue of insufficient privileges on the user account used to log in to ROBO3T and access MongoDB. You can follow this link. It points to a similar issue on Robo3Ts Github. You can use MongoDB Compass to connect to remote/Atlas MongoDB instances too. It is much user friendly.
This worked for me. Just set MongoDB Roles to atlasAdmin#admin.

mongodb tables disappereared somehow

I am using mongodb 3.2.11 in Ubuntu Zesty 17.04 and I am connecting from Nodejs 4.6 to mongodb in HTTPS, the database server is bound to its own address (127.0.0.1) and I have created a user besides admin for read/write to the database.
Although, most of my tables were certainly dropped somehow, only users (empty) and sessions table were left.
I grepped my logs for "drop" with grep -r "drop" and got no results. Despite I am using very recent versions of the software and made some security measures they don't seem enough. At this time I don't need to recover the data, but I wanted to know what else should I be looking at?
Try to use "show collections" in the mongo shell in ubuntu and see if the collections are shown after doing "use dbnamehere".

how to show my users collection with mongodb

I'm sorry for this (peraphs) stupid question ... I install meteor and mongodb in my windows computer and i start to write some apps. I don't understand how to use mongo for shoving my db app ... i open one shell in my app dir and launch mongod, in one more shell in the same folder i start mongo.
show dbs
local
use local
switched to db local
show collections
startup_log
system.indexes
Where are my collections? Where is users collection?
When your app is running use this command on a separate command line mongo 127.0.0.1:3001
Meteor keeps the collections in this server. After you run mongo on this server, by writing use meteor you can use db specific to your running app. And then you can display your collections with db.getCollectionNames()
Meteor uses a library called Minimongo that's why it doesn't display if you run show dbs on your mongo shell.
By default it points to port 3001 hence if you are using Robomongo you can just make the set up to watch that port.
To display all your MongoDB collections using the shell, you may check this answer:
How to list all collections in the mongo shell?
You may also use a MongoDB GUI Tool such Robomongo