summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMatt Cotter <matt.cotter@mongodb.com>2016-07-19 10:27:12 -0400
committerMatt Cotter <matt.cotter@mongodb.com>2016-08-12 16:28:15 -0400
commit517f21d8461d132496d5e5a748e4470ad33650f9 (patch)
tree673476ea7d0f0e9c62476a93358a9a3d673f3551
parent6adf7407a8fa4c2b5c9d623376101dbbc3c23bad (diff)
downloadmongo-517f21d8461d132496d5e5a748e4470ad33650f9.tar.gz
SERVER-25357 expose read concern setter for shell mongo object
-rw-r--r--src/mongo/shell/bulk_api.js27
-rw-r--r--src/mongo/shell/collection.js5
-rw-r--r--src/mongo/shell/mongo.js24
3 files changed, 44 insertions, 12 deletions
diff --git a/src/mongo/shell/bulk_api.js b/src/mongo/shell/bulk_api.js
index 13f9f5ec25c..16eb1687f60 100644
--- a/src/mongo/shell/bulk_api.js
+++ b/src/mongo/shell/bulk_api.js
@@ -881,17 +881,22 @@ var _bulk_api_module = (function() {
// Get command collection
var cmdColl = collection._db.getCollection('$cmd');
// Bypass runCommand to ignore slaveOk and read pref settings
- result = new DBQuery(collection.getMongo(),
- collection._db,
- cmdColl,
- cmdColl.getFullName(),
- cmd,
- {} /* proj */,
- -1 /* limit */,
- 0 /* skip */,
- 0 /* batchSize */,
- 0 /* flags */)
- .next();
+ var cursor = new DBQuery(collection.getMongo(),
+ collection._db,
+ cmdColl,
+ cmdColl.getFullName(),
+ cmd,
+ {} /* proj */,
+ -1 /* limit */,
+ 0 /* skip */,
+ 0 /* batchSize */,
+ 0 /* flags */);
+ var rc = collection.getMongo().getReadConcern();
+ if (rc) {
+ cursor.readConcern(rc);
+ }
+
+ result = cursor.next();
if (result.ok == 0) {
throw new WriteCommandError(result);
diff --git a/src/mongo/shell/collection.js b/src/mongo/shell/collection.js
index dbb6b31350d..83c3a6f4f48 100644
--- a/src/mongo/shell/collection.js
+++ b/src/mongo/shell/collection.js
@@ -272,6 +272,11 @@ DBCollection.prototype.find = function(query, fields, limit, skip, batchSize, op
cursor.readPref(readPrefMode, connObj.getReadPrefTagSet());
}
+ var rc = connObj.getReadConcern();
+ if (rc) {
+ cursor.readConcern(rc);
+ }
+
return cursor;
};
diff --git a/src/mongo/shell/mongo.js b/src/mongo/shell/mongo.js
index 58c6d00ad81..c7ba018358a 100644
--- a/src/mongo/shell/mongo.js
+++ b/src/mongo/shell/mongo.js
@@ -57,7 +57,7 @@ Mongo.prototype.getDB = function(name) {
};
Mongo.prototype.getDBs = function() {
- var res = this.getDB("admin").runCommand({"listDatabases": 1});
+ var res = this.adminCommand({"listDatabases": 1});
if (!res.ok)
throw _getErrorWithCode(res, "listDatabases failed:" + tojson(res));
return res;
@@ -171,6 +171,28 @@ Mongo.prototype.getReadPref = function() {
return obj;
};
+/**
+ * Sets the read concern.
+ *
+ * @param level {string} read concern level to use. Pass null to disable read concern.
+ */
+Mongo.prototype.setReadConcern = function(level) {
+ if (!level) {
+ this._readConcernLevel = undefined;
+ } else if (level === "local" || level === "majority") {
+ this._readConcernLevel = level;
+ } else {
+ throw Error("Invalid read concern.");
+ }
+};
+
+/**
+ * Gets the read concern.
+ */
+Mongo.prototype.getReadConcern = function() {
+ return this._readConcernLevel;
+};
+
connect = function(url, user, pass) {
if (user && !pass)
throw Error("you specified a user and not a password. " +