summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJonathan Reams <jbreams@mongodb.com>2015-10-28 14:55:21 -0400
committerJonathan Reams <jbreams@mongodb.com>2015-10-29 14:37:06 -0400
commit86c1719ed07cd56d78ceaad821cfe10f3e5b2d44 (patch)
treee842c68f657dbfd90fcb08fd78d79e82e8c45ce8
parent9d7413280fb706e037082ea84442bb83579df58c (diff)
downloadmongo-86c1719ed07cd56d78ceaad821cfe10f3e5b2d44.tar.gz
SERVER-20146 add readConcern to DBQuery shell helpers
-rw-r--r--src/mongo/shell/collection.js8
-rw-r--r--src/mongo/shell/query.js13
2 files changed, 19 insertions, 2 deletions
diff --git a/src/mongo/shell/collection.js b/src/mongo/shell/collection.js
index ee78eda2377..65a31a1cb3e 100644
--- a/src/mongo/shell/collection.js
+++ b/src/mongo/shell/collection.js
@@ -54,7 +54,7 @@ DBCollection.prototype.help = function () {
print("\tdb." + shortName + ".find(...).limit(n)");
print("\tdb." + shortName + ".find(...).skip(n)");
print("\tdb." + shortName + ".find(...).sort(...)");
- print("\tdb." + shortName + ".findOne([query])");
+ print("\tdb." + shortName + ".findOne([query], [fields], [options], [readConcern])");
print("\tdb." + shortName + ".findOneAndDelete( filter, <optional params> ) - delete first matching document, optional parameters are: projection, sort, maxTimeMS");
print("\tdb." + shortName + ".findOneAndReplace( filter, replacement, <optional params> ) - replace first matching document, optional parameters are: projection, sort, maxTimeMS, upsert, returnNewDocument");
print("\tdb." + shortName + ".findOneAndUpdate( filter, update, <optional params> ) - update first matching document, optional parameters are: projection, sort, maxTimeMS, upsert, returnNewDocument");
@@ -204,10 +204,14 @@ DBCollection.prototype.find = function( query , fields , limit , skip, batchSize
return cursor;
}
-DBCollection.prototype.findOne = function( query , fields, options ){
+DBCollection.prototype.findOne = function( query , fields, options, readConcern ){
var cursor = this.find(query, fields, -1 /* limit */, 0 /* skip*/,
0 /* batchSize */, options);
+ if ( readConcern ) {
+ cursor = cursor.readConcern(readConcern);
+ }
+
if ( ! cursor.hasNext() )
return null;
var ret = cursor.next();
diff --git a/src/mongo/shell/query.js b/src/mongo/shell/query.js
index 7b8190d526a..119823858be 100644
--- a/src/mongo/shell/query.js
+++ b/src/mongo/shell/query.js
@@ -30,6 +30,7 @@ DBQuery.prototype.help = function () {
print("\t.skip(<n>)")
print("\t.batchSize(<n>) - sets the number of docs to return per getMore")
print("\t.hint({...})")
+ print("\t.readConcern(<level>)")
print("\t.readPref(<mode>, <tagset>)")
print("\t.count(<applySkipLimit>) - total # of objects matching query. by default ignores skip,limit")
print("\t.size() - total # of objects cursor would return, honors skip,limit")
@@ -199,6 +200,10 @@ DBQuery.prototype._convertToCommand = function(canAttachReadPref) {
cmd["snapshot"] = this._query.$snapshot;
}
+ if ("readConcern" in this._query) {
+ cmd["readConcern"] = this._query.readConcern;
+ }
+
if ((this._options & DBQuery.Option.tailable) != 0) {
cmd["tailable"] = true;
}
@@ -431,6 +436,14 @@ DBQuery.prototype.maxTimeMS = function( maxTimeMS ) {
return this._addSpecial( "$maxTimeMS" , maxTimeMS );
}
+DBQuery.prototype.readConcern = function( level ) {
+ var readConcernObj = {
+ level: level
+ };
+
+ return this._addSpecial( "readConcern", readConcernObj );
+}
+
/**
* Sets the read preference for this cursor.
*