Using Robo 3T 1.1 on macOS Sierra 10.12.5 (although this probably applies to all platforms)

If I re-run a command that used ES6 let to define a variable, it errors with TypeError: redeclaration of let. Same issue with const. I guess a new shell needs to be created for each re-run.
To replicate (assuming a database with a users collection):
let _id = 'x';
db.users.findOne({ _id });
Run the above script, then re-run with the green play button or cmd+enter
Hi @mjmasn , thanks for the report.
I agree that behavior is not very user friendly, but seems like it is design intent of mongo shell.
Note that Robo 3T (Robomongo) embeds the mongo shell which means Robo shell should behave identical as mongo shell. The same script should work on a new Robo shell.
I just confirmed with mongoshell that the behavior is the same. Please see it below.
C:\Program Files\MongoDB\Server\3.4\bin>mongo
MongoDB shell version v3.4.3
connecting to: mongodb://127.0.0.1:27017
MongoDB server version: 3.4.3
...
> let coll = 'Bills'; db.getCollection(coll).find({});
{ "_id" : ObjectId("59228b0574d828afae4876cd"), "sum" : 20 }
{ "_id" : ObjectId("59228b0574d828afae4876ce"), "sum" : 20 }
...
> let coll = 'Bills'; db.getCollection(coll).find({});
2017-06-22T11:15:48.029+0300 E QUERY [thread1] TypeError: redeclaration of let coll :
@(shell):1:5
Hey @mjmasn, you could wrap them with { and } and it should allow you to re-run again without that error.
{
let _id = 'x';
db.users.findOne({ _id });
}
@santochen ahh of course! Thanks :)
So is there a reason this couldn't be the default behaviour, i.e. wrapping every query before execution. Or is there a use case for the current behaviour of running in the same context?
Thanks to santochen for info + fix. Option to enclose could be in the form of an "E6 button"
I feel like this behavior makes sense in the context of a shell, because there is no run button. I think in a GUI like 3T it makes less sense because it's reasonably expectable for a user to re-run a query. Would it be possible to recreate the shell instance on every run so everything is fresh?
Another workaround might be to run the shell once to define your variables then run it with the queries afterward.
I think a button to clear/restart the mongo shell session would be useful. Best work around I have found so far is copy and paste in a new tab.
Most helpful comment
Hey @mjmasn, you could wrap them with
{and}and it should allow you to re-run again without that error.