diff options
author | cchilds1 <cchilds1@binghamton.edu> | 2019-08-09 10:57:03 -0400 |
---|---|---|
committer | cchilds1 <cchilds1@binghamton.edu> | 2019-08-09 10:57:03 -0400 |
commit | adb75a05a64e7d3a4afd8ae0ded6c183dbf0449f (patch) | |
tree | f54be79e2d92f43bbaec19e06fb78793b308b4a0 /jstests/noPassthrough/shell_bson_obj_to_array.js | |
parent | f14d9c4c07e69c2109de0af059123060c73cdd77 (diff) | |
download | mongo-adb75a05a64e7d3a4afd8ae0ded6c183dbf0449f.tar.gz |
SERVER-42664 add bsonObjToArray to shell
Diffstat (limited to 'jstests/noPassthrough/shell_bson_obj_to_array.js')
-rw-r--r-- | jstests/noPassthrough/shell_bson_obj_to_array.js | 33 |
1 files changed, 33 insertions, 0 deletions
diff --git a/jstests/noPassthrough/shell_bson_obj_to_array.js b/jstests/noPassthrough/shell_bson_obj_to_array.js new file mode 100644 index 00000000000..0dc4dc91bd4 --- /dev/null +++ b/jstests/noPassthrough/shell_bson_obj_to_array.js @@ -0,0 +1,33 @@ +/* + * Tests that bsonObjToArray converts BSON objects to JS arrays. + */ + +(function() { +'use strict'; +const conn = MongoRunner.runMongod(); +const db = conn.getDB('test'); +const tests = []; + +tests.push(function objToArrayOk() { + assert.eq([1, 2], bsonObjToArray({"a": 1, "b": 2})); +}); + +tests.push(function sortKeyToArrayOk() { + assert.commandWorked(db.test.insert({_id: 1, a: 2, b: 2, c: 3})); + assert.commandWorked(db.test.insert({_id: 2, a: 2, b: 3, c: 4})); + const findCommand = { + find: 'test', + projection: {sortKey: {$meta: 'sortKey'}, _id: 0, a: 0, b: 0, c: 0}, + sort: {a: 1, b: 1}, + }; + const res1 = new DBCommandCursor(db, db.runCommand(findCommand)).toArray(); + assert.eq([2, 2], bsonObjToArray(res1[0]["sortKey"])); + assert.eq([2, 3], bsonObjToArray(res1[1]["sortKey"])); +}); +tests.forEach((test) => { + jsTest.log(`Starting test '${test.name}'`); + test(); +}); + +MongoRunner.stopMongod(conn); +})();
\ No newline at end of file |