[SERVER-29407] BadValue error when passing readPreference option to usersInfo on a mongos only Created: 31/May/17  Updated: 06/Dec/22  Resolved: 09/Jan/20

Status: Closed
Project: Core Server
Component/s: Sharding
Affects Version/s: 3.4.4
Fix Version/s: None

Type: Bug Priority: Major - P3
Reporter: Peter Schmidt Assignee: [DO NOT USE] Backlog - Sharding Team
Resolution: Won't Fix Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Attachments: PNG File macOS expect test to reproduce this error.png     File mongos_usersinfo_error.js    
Issue Links:
Related
related to COMPASS-1930 Connect To Secondary "not authorized"... Closed
related to NODE-1012 MongoError: "$queryOptions" is not a ... Closed
related to SERVER-22516 mongos should apply client's read pre... Backlog
Assigned Teams:
Sharding
Operating System: ALL
Steps To Reproduce:

Please run attached mongos_usersinfo_error.js test script, e.g. if placed inside jstests/sharding with command:

python buildscripts/resmoke.py jstests/sharding/mongos_usersinfo_error.js

Expect to see the following output:

Participants:

 Description   

When I run the following mongo shell command against a mongos:

db.runCommand({$query:{usersInfo:1}, $readPreference:{mode: 'primary'}})

I get the response error:

{
	"ok" : 0,
	"errmsg" : "\"$queryOptions\" is not a valid argument to usersInfo",
	"code" : 2,
	"codeName" : "BadValue"
}

I have also observed similar behaviour in NODE-1012.

I do not get such an error when:

  • Connecting to a standalone without auth enabled

    { "users" : [ ], "ok" : 1 }

  • Connecting to a replica set primary or secondary(1) without auth enabled

    { "users" : [ ], "ok" : 1 }

  • Connecting to a replica set primary or secondary(1) with auth enabled and not logged in

    "errmsg" : "not authorized on test to execute command { usersInfo: 1.0} "

  • Connecting to a replica set primary or secondary(1) with auth enabled and logged in with appropriate privileges, I get no error and a document containing a list of users and roles

    {
    	"users" : [
    		{
    			"_id" : "admin.limited",
    			"user" : "limited",
    			"db" : "admin",
    			"roles" : [
    				{
    					"role" : "readWrite",
    					"db" : "food"
    				},
    				{
    					"role" : "read",
    					"db" : "foo"
    				}
    			]
    		},
    		{
    			"_id" : "admin.user",
    			"user" : "user",
    			"db" : "admin",
    			"roles" : [
    				{
    					"role" : "dbAdminAnyDatabase",
    					"db" : "admin"
    				},
    				{
    					"role" : "readWriteAnyDatabase",
    					"db" : "admin"
    				},
    				{
    					"role" : "userAdminAnyDatabase",
    					"db" : "admin"
    				},
    				{
    					"role" : "clusterAdmin",
    					"db" : "admin"
    				}
    			]
    		}
    	],
    	"ok" : 1
    }
    

(1) After the obligatory rs.slaveOk() of course.



 Comments   
Comment by Sheeri Cabral (Inactive) [ 09/Jan/20 ]

This is inconsistent and should either work or not work, but it's not worth the cycles to actually fix it at this point in time.

Comment by Peter Schmidt [ 16/Jun/17 ]

Thank you for asking schwerin and sorry for my delay in replying.

It is my understanding that this issue is a specific case of SERVER-22516, for the usersInfo command. That ticket links to this server specification which states:

The generic command method SHOULD allow an optional read preference argument.

Comment by Andy Schwerin [ 09/Jun/17 ]

I believe the only prescribed way to set read preference in the mongo shell is to do it on the Mongo object, using the setReadPref method. That the following works sometimes is the result of an implementation detail.

db.runCommand({$query:{usersInfo:1}, $readPreference:{mode: 'primary'}})

Are you aware of any documentation indicating that the above should work?

Generated at Thu Feb 08 04:20:47 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.