mirror of
https://github.com/mongodb/mongo.git
synced 2024-11-30 17:10:48 +01:00
SERVER-18557 remove usage of $cmd.findOne from shell and jstests
This commit is contained in:
parent
6351419085
commit
87a7b96365
@ -26,5 +26,5 @@ assert.eq( 2 , t.find( q ).skip(48).limit(5).size() , "I" );
|
||||
assert.eq( 20 , t.find().limit(20).size() , "J" );
|
||||
|
||||
assert.eq( 0 , t.find().skip(120).size() , "K" );
|
||||
assert.eq( 1 , db.$cmd.findOne( { count: "count5" } )["ok"] , "L" );
|
||||
assert.eq( 1 , db.$cmd.findOne( { count: "count5", skip: 120 } )["ok"] , "M" );
|
||||
assert.eq( 1 , db.runCommand( { count: "count5" } )["ok"] , "L" );
|
||||
assert.eq( 1 , db.runCommand( { count: "count5", skip: 120 } )["ok"] , "M" );
|
||||
|
@ -1,9 +1,9 @@
|
||||
db.jstests_error1.drop();
|
||||
|
||||
// test 1
|
||||
db.$cmd.findOne({reseterror:1});
|
||||
assert( db.$cmd.findOne({getlasterror:1}).err == null, "A" );
|
||||
assert( db.$cmd.findOne({getpreverror:1}).err == null, "B" );
|
||||
db.runCommand({reseterror:1});
|
||||
assert( db.runCommand({getlasterror:1}).err == null, "A" );
|
||||
assert( db.runCommand({getpreverror:1}).err == null, "B" );
|
||||
|
||||
db.resetError();
|
||||
assert( db.getLastError() == null, "C" );
|
||||
@ -11,9 +11,9 @@ assert( db.getPrevError().err == null , "preverror 1" );
|
||||
|
||||
// test 2
|
||||
|
||||
db.$cmd.findOne({forceerror:1});
|
||||
assert( db.$cmd.findOne({getlasterror:1}).err != null, "D" );
|
||||
assert( db.$cmd.findOne({getpreverror:1}).err != null, "E" );
|
||||
db.runCommand({forceerror:1});
|
||||
assert( db.runCommand({getlasterror:1}).err != null, "D" );
|
||||
assert( db.runCommand({getpreverror:1}).err != null, "E" );
|
||||
|
||||
|
||||
assert( db.getLastError() != null, "F" );
|
||||
@ -21,14 +21,14 @@ assert( db.getPrevError().err != null , "preverror 2" );
|
||||
assert( db.getPrevError().nPrev == 1, "G" );
|
||||
|
||||
db.jstests_error1.findOne();
|
||||
assert( db.$cmd.findOne({getlasterror:1}).err == null, "H" );
|
||||
assert( db.$cmd.findOne({getpreverror:1}).err != null, "I" );
|
||||
assert( db.$cmd.findOne({getpreverror:1}).nPrev == 2, "J" );
|
||||
assert( db.runCommand({getlasterror:1}).err == null, "H" );
|
||||
assert( db.runCommand({getpreverror:1}).err != null, "I" );
|
||||
assert( db.runCommand({getpreverror:1}).nPrev == 2, "J" );
|
||||
|
||||
db.jstests_error1.findOne();
|
||||
assert( db.$cmd.findOne({getlasterror:1}).err == null, "K" );
|
||||
assert( db.$cmd.findOne({getpreverror:1}).err != null, "L" );
|
||||
assert( db.$cmd.findOne({getpreverror:1}).nPrev == 3, "M" );
|
||||
assert( db.runCommand({getlasterror:1}).err == null, "K" );
|
||||
assert( db.runCommand({getpreverror:1}).err != null, "L" );
|
||||
assert( db.runCommand({getpreverror:1}).nPrev == 3, "M" );
|
||||
|
||||
db.resetError();
|
||||
db.forceError();
|
||||
@ -37,5 +37,5 @@ assert( db.getLastError() == null , "getLastError 5" );
|
||||
assert( db.getPrevError().err != null , "preverror 3" );
|
||||
|
||||
// test 3
|
||||
db.$cmd.findOne({reseterror:1});
|
||||
assert( db.$cmd.findOne({getpreverror:1}).err == null, "N" );
|
||||
db.runCommand({reseterror:1});
|
||||
assert( db.runCommand({getpreverror:1}).err == null, "N" );
|
||||
|
@ -45,11 +45,10 @@ DB.prototype.commandHelp = function( name ){
|
||||
}
|
||||
|
||||
// utility to attach readPreference if needed.
|
||||
DB.prototype._attachReadPreferenceToCommand = function (cmdObj) {
|
||||
DB.prototype._attachReadPreferenceToCommand = function (cmdObj, readPref) {
|
||||
"use strict";
|
||||
var readPref = this.getMongo().getReadPref();
|
||||
// if the user has not set a readpref, return the original cmdObj
|
||||
if (readPref === null) {
|
||||
if ((readPref === null) || typeof(readPref) !== "object") {
|
||||
return cmdObj;
|
||||
}
|
||||
|
||||
@ -86,21 +85,24 @@ DB.prototype.commandHelp = function( name ){
|
||||
};
|
||||
|
||||
// Like runCommand but applies readPreference if one has been set
|
||||
// on the connection. Also sets options automatically.
|
||||
// on the connection. Also sets slaveOk if a (non-primary) readPref has been set.
|
||||
DB.prototype.runReadCommand = function (obj, extra) {
|
||||
"use strict";
|
||||
|
||||
// Support users who call this function with a string commandName, e.g.
|
||||
// db.runReadCommand("commandName", {arg1: "value", arg2: "value"}).
|
||||
var mergedObj = (typeof(obj) === "string") ? this._mergeCommandOptions(obj, extra) : obj;
|
||||
var cmdObjWithReadPref = this._attachReadPreferenceToCommand(obj);
|
||||
var cmdObjWithReadPref =
|
||||
this._attachReadPreferenceToCommand(mergedObj,
|
||||
this.getMongo().getReadPref());
|
||||
|
||||
var options = 0;
|
||||
// automatically set slaveOk if readPreference is anything but primary
|
||||
// We automatically set slaveOk if readPreference is anything but primary.
|
||||
if (this.getMongo().getReadPrefMode() !== "primary") {
|
||||
options |= 4;
|
||||
}
|
||||
|
||||
// allow options to be overridden
|
||||
// extra is not used since mergedObj is an object
|
||||
// The 'extra' parameter is not used as we have already created a merged command object.
|
||||
return this.runCommand(cmdObjWithReadPref, null, options);
|
||||
};
|
||||
|
||||
|
@ -160,25 +160,15 @@ var DBExplainQuery = (function() {
|
||||
var explainCmd = {explain: innerCmd};
|
||||
explainCmd["verbosity"] = this._verbosity;
|
||||
|
||||
// We explicitly run a find against the $cmd collection instead of using the
|
||||
// runCommand helper so that we can set a read preference on the command.
|
||||
var cmdColl = this._query._db.getCollection("$cmd");
|
||||
var cmdQuery = cmdColl.find(explainCmd,
|
||||
{}, // projection
|
||||
-1, // limit
|
||||
0, // skip
|
||||
0, // batchSize
|
||||
this._query._options);
|
||||
var explainDb = this._query._db;
|
||||
|
||||
// Handle read preference.
|
||||
if ("$readPreference" in this._query._query) {
|
||||
// A read preference was set on the query. Pull the read pref up so that it is
|
||||
// set on the explain command.
|
||||
var prefObj = this._query._query.$readPreference;
|
||||
cmdQuery.readPref(prefObj.mode, prefObj.tags);
|
||||
explainCmd = explainDb._attachReadPreferenceToCommand(explainCmd, prefObj);
|
||||
}
|
||||
|
||||
var explainResult = cmdQuery.next();
|
||||
var explainResult = explainDb.runCommand(explainCmd, null, this._query._options);
|
||||
|
||||
if (!explainResult.ok && explainResult.code === CMD_NOT_FOUND_CODE) {
|
||||
// One of the shards doesn't have the explain command available. Retry using
|
||||
// the legacy $explain format, which should be supported by all shards.
|
||||
|
Loading…
Reference in New Issue
Block a user