Richard O'Neil
Richard O'Neil

Reputation: 163

MongoDb C# driver - test authentication mode

Using the C# MongoDb driver, is there a way to query a server to find out if it was started with:

mongod --auth or just mongod?

Thanks.

Upvotes: 1

Views: 254

Answers (1)

bitswamp
bitswamp

Reputation: 26

There is a ticket on the MongoDB tracker indicating the getCmdLineOpts command can be used to get the auth mode of the server.

db.runCommand("getCmdLineOpts")

returns

{
  "argv" : [ 
    "mongod", 
    "--config", 
    "mongodb.conf"
  ],
  "parsed" : {
    "auth" : "true",
    "config" : "mongodb.conf",
    ...
  },
  "ok" : 1
}

If --auth was passed on the command line it will appear in the argv and parsed nodes; if it was set in mongodb.conf it will only appear in the parsed node.

Upvotes: 1

Related Questions