User field missing in system.profile collection when connecting with Mongos - mongodb

We have a MongoDB cluster and clients connecting to it through a Mongos instance. The individual mongo(s) in the cluster are all running with --auth, and the Mongo use a --keyfile when communicating with them. We are profiling slow queries but are not getting the user names on queries that go through Mongo.
To make it clearer:
If I connect directly to one of the Mongo, authenticate, and run a query, then I can look in the system.profile collection afterwards, and the user field will be populated with my username.
If I connect through mongos, authenticate, and run a query, then the system.profile collection contains profiling info about the query, but the user field is blank.
The authentication is required, I can't run a query through Mongo without authenticating first, but the user name just doesn't seem to be included in the profiling info, and we'd really like to be able to see it.
Any ideas? Any alterations I can make to our configuration?

Just to actually add an answer:
As Ren stated in his comment, he filed a ticket, as this is related to a bug.

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.

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.

system.profile collection empty even though mongod started with profile level 2

Specs: Win10 64bit, MongoDB v3.6.3
I'm having trouble profiling MongoDB. I have some slow queries for which I wanted to see more details, so I started mongod with --profile 2. I checked with MongoDB console if the profiler was enabled with db.getProfilingLevel() which reports 2 correctly.
However, after running some queries from my application (.Net, official driver) which I'm sure are working as I get correct results, the system.profile collection is still empty (db.system.profile.findOne() returns null).
I'm currently out of ideas what could be the problem and google searches didn't lead to any interesting results. Sometimes after a while the mongod contains this output, but it's not generated in response to any query:
.sessions: CannotImplicitlyCreateCollection: request doesn't allow collection to be created implicitly
2018-04-18T20:10:47.249+0200 I - [thread53] Creating profile collection: config.system.profile
2018-04-18T20:10:47.250+0200 W - [thread53] Caught Assertion while trying to profile update against config.system.sessions: CannotImplicitlyCreateCollection: request doesn't allow collection to be created implicitly

Mongodb not listing collections when connecting remotely from CentOS

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

Mongos authentication

We have 9 mongo nodes in our environment with:
1 mongos
3 config servers (mongod --configSvr)
9 mongod servers (shards or members of sharded replica-sets)
and we are trying to implement authentication on them.
I have done this in the past with a single server and it was really easy:
just add the admin user to the admin database
add a user on each database
I had to restart mongod with --auth option, but here it doesn't seem to work.
I've added the admin account to our mongos and for our sharded databases; I tried to authenticate as the user I had just created, but it didn't work.
I've tried creating an admin user on each database, and the other user accounts that we need, but it still didn't work.
I also tried making sure all of our mongo servers were running with the --keyFile option specified either on the command-line or in their /etc/mongodb.conf files, but that didn't seem to help.
When I try to authenticate as a given user, like so:
db.auth("user","passwd")
it fails and returns 0, as in false; not non-zero.
I seriously need all the help I can get, so please at least leave some suggestions on things I could try--I can't overstress this, any help is more than welcome since I don't seem to be getting anywhere just from following the official docs on managing/administrating mongo sharded clusters.
In a sharded cluster you should use --keyFile to allow all the members of the cluster to authenticate to each other. When you use this option, --auth is "assumed". Since there've been several version changes since you asked this question, the roles assigned to users are more granular now - you would need to have a 'clusterAdmin', 'userAdmin', 'dbAdmin', etc.
This page has more details about how to configure security in MongoDB for a sharded cluster.