summaryrefslogtreecommitdiff
path: root/src/mongo/scripting
diff options
context:
space:
mode:
authorYoonsoo Kim <yoonsoo.kim@mongodb.com>2021-06-24 04:46:41 +0000
committerEvergreen Agent <no-reply@evergreen.mongodb.com>2021-07-15 01:00:07 +0000
commit922e712eb2a87d1d31a88e4cbbe43eaebaa9c009 (patch)
treea565748dc58d2404f7f87c9554f04c8277729a0b /src/mongo/scripting
parent816ca8f1961a487ea789c969ecc09730929581ae (diff)
downloadmongo-922e712eb2a87d1d31a88e4cbbe43eaebaa9c009.tar.gz
SERVER-57462 Change the shell to use OP_MSG for exhaust queries instead of OP_QUERY
Diffstat (limited to 'src/mongo/scripting')
-rw-r--r--src/mongo/scripting/mozjs/cursor.cpp14
-rw-r--r--src/mongo/scripting/mozjs/cursor.h3
-rw-r--r--src/mongo/scripting/mozjs/mongo.cpp37
3 files changed, 15 insertions, 39 deletions
diff --git a/src/mongo/scripting/mozjs/cursor.cpp b/src/mongo/scripting/mozjs/cursor.cpp
index f90bcb924db..23cb6fd7082 100644
--- a/src/mongo/scripting/mozjs/cursor.cpp
+++ b/src/mongo/scripting/mozjs/cursor.cpp
@@ -41,7 +41,7 @@
namespace mongo {
namespace mozjs {
-const JSFunctionSpec CursorInfo::methods[8] = {
+const JSFunctionSpec CursorInfo::methods[9] = {
MONGO_ATTACH_JS_CONSTRAINED_METHOD_NO_PROTO(close, CursorInfo),
MONGO_ATTACH_JS_CONSTRAINED_METHOD_NO_PROTO(hasNext, CursorInfo),
MONGO_ATTACH_JS_CONSTRAINED_METHOD_NO_PROTO(next, CursorInfo),
@@ -49,6 +49,7 @@ const JSFunctionSpec CursorInfo::methods[8] = {
MONGO_ATTACH_JS_CONSTRAINED_METHOD_NO_PROTO(getId, CursorInfo),
MONGO_ATTACH_JS_CONSTRAINED_METHOD_NO_PROTO(readOnly, CursorInfo),
MONGO_ATTACH_JS_CONSTRAINED_METHOD_NO_PROTO(isClosed, CursorInfo),
+ MONGO_ATTACH_JS_CONSTRAINED_METHOD_NO_PROTO(hasMoreToCome, CursorInfo),
JS_FS_END,
};
@@ -151,5 +152,16 @@ void CursorInfo::Functions::isClosed::call(JSContext* cx, JS::CallArgs args) {
args.rval().setBoolean(cursor->isDead());
}
+void CursorInfo::Functions::hasMoreToCome::call(JSContext* cx, JS::CallArgs args) {
+ auto cursor = getCursor(args);
+
+ if (!cursor) {
+ args.rval().setBoolean(false);
+ return;
+ }
+
+ args.rval().setBoolean(cursor->hasMoreToCome());
+}
+
} // namespace mozjs
} // namespace mongo
diff --git a/src/mongo/scripting/mozjs/cursor.h b/src/mongo/scripting/mozjs/cursor.h
index 6aa610f80b6..6373d21fe04 100644
--- a/src/mongo/scripting/mozjs/cursor.h
+++ b/src/mongo/scripting/mozjs/cursor.h
@@ -52,9 +52,10 @@ struct CursorInfo : public BaseInfo {
MONGO_DECLARE_JS_FUNCTION(objsLeftInBatch);
MONGO_DECLARE_JS_FUNCTION(readOnly);
MONGO_DECLARE_JS_FUNCTION(getId);
+ MONGO_DECLARE_JS_FUNCTION(hasMoreToCome);
};
- static const JSFunctionSpec methods[8];
+ static const JSFunctionSpec methods[9];
static const char* const className;
static const unsigned classFlags = JSCLASS_HAS_PRIVATE;
diff --git a/src/mongo/scripting/mozjs/mongo.cpp b/src/mongo/scripting/mozjs/mongo.cpp
index 676f48692b1..26dd43d33e8 100644
--- a/src/mongo/scripting/mozjs/mongo.cpp
+++ b/src/mongo/scripting/mozjs/mongo.cpp
@@ -61,7 +61,6 @@ namespace mozjs {
const JSFunctionSpec MongoBase::methods[] = {
MONGO_ATTACH_JS_CONSTRAINED_METHOD_NO_PROTO(auth, MongoExternalInfo),
MONGO_ATTACH_JS_CONSTRAINED_METHOD_NO_PROTO(close, MongoExternalInfo),
- MONGO_ATTACH_JS_CONSTRAINED_METHOD_NO_PROTO(cursorFromId, MongoExternalInfo),
MONGO_ATTACH_JS_CONSTRAINED_METHOD_NO_PROTO(cursorHandleFromId, MongoExternalInfo),
MONGO_ATTACH_JS_CONSTRAINED_METHOD_NO_PROTO(find, MongoExternalInfo),
MONGO_ATTACH_JS_CONSTRAINED_METHOD_NO_PROTO(generateDataKey, MongoExternalInfo),
@@ -360,9 +359,6 @@ void MongoBase::Functions::find::call(JSContext* cx, JS::CallArgs args) {
int batchSize = ValueWriter(cx, args.get(5)).toInt32();
int options = ValueWriter(cx, args.get(6)).toInt32();
- // The shell only calls this method when it wants to test OP_QUERY.
- options |= DBClientCursor::QueryOptionLocal_forceOpQuery;
-
std::unique_ptr<DBClientCursor> cursor(conn->query(NamespaceString(ns),
q,
nToReturn,
@@ -436,39 +432,6 @@ void MongoBase::Functions::logout::call(JSContext* cx, JS::CallArgs args) {
ValueReader(cx, args.rval()).fromBSON(ret.getOwned(), nullptr, false);
}
-void MongoBase::Functions::cursorFromId::call(JSContext* cx, JS::CallArgs args) {
- auto scope = getScope(cx);
-
- if (!(args.length() == 2 || args.length() == 3))
- uasserted(ErrorCodes::BadValue, "cursorFromId needs 2 or 3 args");
-
- if (!scope->getProto<NumberLongInfo>().instanceOf(args.get(1)))
- uasserted(ErrorCodes::BadValue, "2nd arg must be a NumberLong");
-
- if (!(args.get(2).isNumber() || args.get(2).isUndefined()))
- uasserted(ErrorCodes::BadValue, "3rd arg must be a js Number");
-
- auto conn = getConnection(args);
-
- std::string ns = ValueWriter(cx, args.get(0)).toString();
-
- long long cursorId = NumberLongInfo::ToNumberLong(cx, args.get(1));
-
- // The shell only calls this method when it wants to test OP_GETMORE.
- auto cursor = std::make_unique<DBClientCursor>(
- conn, NamespaceString(ns), cursorId, 0, DBClientCursor::QueryOptionLocal_forceOpQuery);
-
- if (args.get(2).isNumber())
- cursor->setBatchSize(ValueWriter(cx, args.get(2)).toInt32());
-
- JS::RootedObject c(cx);
- scope->getProto<CursorInfo>().newObject(&c);
-
- setCursor(scope, c, std::move(cursor), args);
-
- args.rval().setObjectOrNull(c);
-}
-
void MongoBase::Functions::cursorHandleFromId::call(JSContext* cx, JS::CallArgs args) {
auto scope = getScope(cx);