-
Type: Bug
-
Resolution: Unresolved
-
Priority: Minor - P4
-
None
-
Affects Version/s: 1.0.5
-
Component/s: AsyncWriter
-
5
Problem Statement/Rationale
MongoSh have mixing behavior when executing code directly and executing string code by using eval or Function.
Steps to Reproduce
Executing the following snippet to reproduce:
1. Create testing object
// Raw code Test = function () { a = dbs.admin.runCommand({rolesInfo: `root`}); console.log(a.constructor.name); return a; } // Using eval eval('global.Test2 = function () { a = dbs.admin.runCommand({rolesInfo: `root`}); console.log(a.constructor.name); return a; }') // Using Function Function('global.Test3 = function () { a = dbs.admin.runCommand({rolesInfo: `root`}); console.log(a.constructor.name); return a; }')()
2. Exectuting each function
> Test()
> Test2()
> Test3()
Expected Results
All 3 test printing Object and roles result. Same behavior since code are the same.
> Test() Object { roles: [ { db: 'admin', role: 'root', roles: [], inheritedRoles: [], isBuiltin: true } ], ok: 1, '$clusterTime': { clusterTime: Timestamp({ t: 1631014883, i: 1 }), signature: { hash: Binary(Buffer.from("eabb594687cc5dd2eab350cd540036c000b25912", "hex"), 0), keyId: Long("6995103262357585924") } }, operationTime: Timestamp({ t: 1631014883, i: 1 }) }
Actual Results
Test2() and Test3() returning Promise instead of Object
> Test2() Promise { roles: [ { db: 'admin', role: 'root', roles: [], inheritedRoles: [], isBuiltin: true } ], ok: 1, '$clusterTime': { clusterTime: Timestamp({ t: 1631014883, i: 1 }), signature: { hash: Binary(Buffer.from("eabb594687cc5dd2eab350cd540036c000b25912", "hex"), 0), keyId: Long("6995103262357585924") } }, operationTime: Timestamp({ t: 1631014883, i: 1 }) }
> Test3() Promise { roles: [ { db: 'admin', role: 'root', roles: [], inheritedRoles: [], isBuiltin: true } ], ok: 1, '$clusterTime': { clusterTime: Timestamp({ t: 1631014883, i: 1 }), signature: { hash: Binary(Buffer.from("eabb594687cc5dd2eab350cd540036c000b25912", "hex"), 0), keyId: Long("6995103262357585924") } }, operationTime: Timestamp({ t: 1631014883, i: 1 }) }
Additional Notes
Because the Promise is returned, code saved on server cannot run as expected in MongoSh.