jstests/auth/explain_auth.js
/**
 * Runs explains of find, count, group, remove, and update. Checks that they either succeed or
 * fail with "not authorized".
 *
 * Takes as input a document 'authSpec' with the following format:
 *   {
 *      find: <bool>,
 *      count: <bool>,
 *      group: <bool>,
 *      remove: <bool>,
 *      update: <bool>
 *   }
 *
 * A true value indicates that the corresponding explain should succeed, whereas a false value
 * indicates that the explain command should not be authorized.
 */
Runs explains of find, count, group, remove, and update. Checks that they either succeed or
fail with "not authorized".



A true value indicates that the corresponding explain should succeed, whereas a false value
indicates that the explain command should not be authorized.
Runs explains of find count group remove and update . Checks that they either succeed or fail with " not authorized " . A true value indicates that the corresponding explain should succeed whereas a false value indicates that the explain command should not be authorized .
function testExplainAuth(authSpec) {
    var cmdResult;
    function assertCmdResult(result, expectSuccess) {
        if (expectSuccess) {
            assert.commandWorked(result);
        }
        else {
            assert.commandFailedWithCode(result, 13);
        }
    }
    cmdResult = db.runCommand({explain: {find: coll.getName()}});
    assertCmdResult(cmdResult, authSpec.find);
    cmdResult = db.runCommand({explain: {count: coll.getName()}});
    assertCmdResult(cmdResult, authSpec.count);
    cmdResult = db.runCommand({
        explain: {
            group: {
                ns: coll.getName(),
                key: "a",
                $reduce: function() { },
                initial: { }
            }
        }
    });
    assertCmdResult(cmdResult, authSpec.group);
    cmdResult = db.runCommand({
        explain: {
            delete: coll.getName(),
            deletes: [ {q: {a: 1}, limit: 1} ]
        }
    });
    assertCmdResult(cmdResult, authSpec.remove);
    cmdResult = db.runCommand({
        explain: {
            update: coll.getName(),
            updates: [ {q: {a: 1}, u: {$set: {b: 1}}} ]
        }
    });
    assertCmdResult(cmdResult, authSpec.update);
}
function testExplainAuth ( authSpec ) { var cmdResult ; function assertCmdResult ( result , expectSuccess ) { if ( expectSuccess ) { assert . commandWorked ( result ) ; } else { assert . commandFailedWithCode ( result , 13 ) ; } } cmdResult = db . runCommand ( { explain : { find : coll . getName ( ) } } ) ; assertCmdResult ( cmdResult , authSpec . find ) ; cmdResult = db . runCommand ( { explain : { count : coll . getName ( ) } } ) ; assertCmdResult ( cmdResult , authSpec . count ) ; cmdResult = db . runCommand ( { explain : { group : { ns : coll . getName ( ) , key : "a" , $reduce : function ( ) { } , initial : { } } } } ) ; assertCmdResult ( cmdResult , authSpec . group ) ; cmdResult = db . runCommand ( { explain : { delete : coll . getName ( ) , deletes : [ { q : { a : 1 } , limit : 1 } ] } } ) ; assertCmdResult ( cmdResult , authSpec . remove ) ; cmdResult = db . runCommand ( { explain : { update : coll . getName ( ) , updates : [ { q : { a : 1 } , u : { $set : { b : 1 } } } ] } } ) ; assertCmdResult ( cmdResult , authSpec . update ) ; }
Runs explains of find, count, group, remove, and update.
Runs explains of find count group remove and update .
// .find() // .count() // .group() // .remove() // .update()