We do not have to repeat use('db') every time
After executing use('db') we don't need to include the command with each run, especially when we want to run the selected line.
At present, if I run some selected lines to run from play ground it doesn't works if the lines doesn't includes the use('db') command.
-
Chris commented
Being able to run the entire paragraph without highlighting would be a great idea, then it isn't so painful to have to write the query and use db, you can just write it and jump around running queries with the hotkey. Cosmos Db Studio does something similar, I think its open source if you'd like to see how.
-
Zsolt commented
Ideally, there could be a drop list on the toolbar to select the DB for the playground. The tool can then execute the "use" command to initialise the context for any execution, keeping the stateless execution model, but improving UX.
I can imagine the drop list flicking to the right value when I actually issue the command "use" .. this isn't necessary, tough.
The current behaviour isn't very different than editing a js file and occasionally feeding it to mongo(sh)
-
Keerthi commented
A behavior similar to mongosh where we establish a stateful session once and then run arbitrary statements any number of times without having to use('db') every time would be desirable.
I reckon for most users this would be the frequent use case. Often times we would go back to a previous statement and run just that. Such a feature would definitely be useful.
Having to use db.getSiblingDB('db').getCollection('coll') in every line feels like we are not in a shell but writing some application code.
-
Carson commented
+1 - being stateless seems cool but is a huge pain for the user. Instead, being able to bind a DB to a specific playground might make more sense for some users.
-
AdminMassimiliano (Admin, MongoDB) commented
We intentionally made playgrounds stateless so they are more flexible and each run is repeatable and does not depend on a database being or not being selected.
However, I see how that can become a pain point for the "run selected lines" use case. For those situations you currently have 2 options:
1. you repeat use('db') multiple times.
2. you use db.getSiblingDB('db').getCollection('coll')... so then you can run the specific statement/command only.