vscode
vscode copied to clipboard
"use" command behavior is finicky
Bug Report
Current Behavior
Specifying the use command followed by a space, the database name, and a semicolon, does not properly select the database. For example:
use dbname;
will produce switched to db dbname; in the Playground Result tab, but a subsequent find db.colname.find({}); on a collection colname containing documents will produce no results.
However, if instead the command is issued as use('dbname'); the subsequent find command does return results.
Expected Behavior/Code
I would expect the use dbname;, followed by a valid find, to return documents in the specified collection. This syntax appears valid according to both mongo and mongosh shell documentation:
https://docs.mongodb.com/manual/reference/mongo-shell/
https://docs.mongodb.com/mongodb-shell/run-commands/
Environment
- MongoDB for VS Code v0.6.12
- OS: macOS Big Sur 11.6
Hi @scoaste-st!
We are aware of this problem and have a ticket to track work on our side: https://jira.mongodb.org/browse/MONGOSH-962
The main issue here is that use dbname; is not valid JavaScript, and we are not in a position where we would want to extend a custom JS parser to handle this specific case. We most likely will make the shell (and thus also vscode) reject input of this form and point the user towards the function-call-style equivalent in the error message.