MongoDB Shell
12 results found
-
mongosh and JSON: normalized output
The CLI commands, like mongosh, can be used in bash scripts to quickly implement reliable data processing pipelines. Thanks to the aggregation pipeline your clients can do pretty complex things with this, despite a small number of lines and zero infrastructure. Unfortunately, in the recent versions, the output of those commands is no longer JSON. When mongosh returns results, it is now in pseudo-JSON, which can no longer be parsed directly by other standard tools like jq. This makes interpreting the results needlessly complicated. In addition, error messages are not output in JSON either (simple unformatted strings in that case),…
2 votesStarting with mongosh 1.6.0, it's now possible to pass a `--json` parameter to mongosh in conjunction with
`--eval`. For example:
$ mongosh $CONNECTION_STRING --eval 'db.coll.stats()' --json=relaxed --quiet | jq '{storageSize,totalSize}'
{
"storageSize": 36864,
"totalSize": 184320
}If instead you are looking for a way to output JSON from a script, you can use `EJSON.stringify(thingToOutput, null, 2)`.
-
Add support for AWS_PROFILE when authMechanism is MONGODB-AWS
Currently, when using MONGODB-AWS, it can only read the following variables:
AWS ACCESS KEY ID
AWS SECRET ACCESS KEY
AWS SESSION TOKENwhich forces you to export credentials or to paste them in the CLI.
AWS has a variable called AWS_PROFILE that will fetch the required values from your credential file, without having to paste them again. This variable is supported by anything using AWS SDK, so mongosh should have support for it as well.
10 votesHi there,
Thank you for your feedback. We wanted to let you know this issue has been resolved starting mongosh version 2.2.0. Please find the latest version of mongosh here: https://www.mongodb.com/try/download/shell.
Please let us know how else we could make your MongoDB Shell experience better!
-
Mongosh connection string thourgh proxy
Greetings,
I need to create a proxy host in my environment so that ALL traffic between client <->Mongo Atlas goes through ONE single host.
Problem is that if I usemongodb+srv://server.example.com/
It returns me one of 50 endpoints to my Atlas cluster.I need something like: connect to this cluster, BUT use this proxy hop server.
1 vote -
Deal with // comments multiline history better
This is a papercut in the legacy shell which would make the modern shell even more usable by comparison...
Currently, both the new and legacy shell have an issue with the way they store a multiline command (eg. when defining an aggregation pipeline) as a single line in its history.
Often (especially for aggregation pipelines) inputted commands will contain // comments. For example, see the code snippet 'var pipeline = [...];' here: https://www.practical-mongodb-aggregations.com/examples/simple-examples/group-and-total.html
The reason why this shell behaviour is problematic is discussed in the Practical MongoDB Aggregations book chapter at https://www.practical-mongodb-aggregations.com/guides/composibility.html
(scroll 2/3 down that page and read the…1 voteStarting with version 1.0.6 of mongosh, single-line comments are replaced with /**/.
There is no simple way to retain multi-line in history but I will split that into a separate suggestion to keep track of it.
-
Allow for session timeouts
For security reasons, it should be possible to configure a session timeout after which, if there has been no activity, the shell disconnects from MongoDB and the user has to reconnect.
0 votes -
Bracket matching and highlighting
Something which I miss from the legacy shell is bracket matching and highlighting, so I can tell when I have too many brackets, or they're in the wrong order
3 votesThis is available starting in version 0.15.5
-
Control-C to cancel current execution only - without exiting from mongo shell
when you started some complex query and realized that it could take time - you want to cancel it. if you press Control-C you will be kicked out of mongo shell. so you have to login back and switch to proper database; probably, set all variables again etc.
there should be option to cancel just current execution leaving you in current session.
1 voteThis is available in mongosh 0.13.1+. When you do Ctrl-C, the shell will attempt to cleanly kill the operation on the server and get you back to the prompt right away.
-
Support .mongorc.js file
A core bit of functionality from the original shell is to support reading from the
.mongorc.js
file in a user's home directory. This feels like core functionality thatmongosh
should support.4 votesThis is available in mongosh 0.10.0+
-
Edit command like the old mongo shell has
It would be nice to have the edit feature of the old mongo shell https://docs.mongodb.com/manual/tutorial/configure-mongo-shell/#use-an-external-editor-in-the-mongo-shell
3 votesThis is completed and released in mongosh 1.1.0.
Let us know if you have any feedback about this feature or about the shell in general.
-
Ability to execute a javascript file from inside the shell
Currently the only way to execute a javascript file from the mongo shell is to re-direct the input at shell login time (e.g. mongo --username <username> ... < myscript.js). It would be helpful to have a way to execute the script from inside the shell via some sort of "run" command (e.g.from inside the shell "run /my/path/myscript.js".
4 votesMongosh 0.10.0+ supports load() which seems to be exactly what you need. Please let me know if that is not what you had in mind.
-
Add history search
Add ability to search through the command history using Cmd/Ctrl+R. It would be nice to also being able to search through the scripts entered with
.editor
1 vote -
Vi mode for MongoDB Shell
Please enable a 'vi' editing mode for the mongo shell.
- Similar to vi mode in bash
- Similar to https://www.npmjs.com/package/mongovi
A first cut of key bindings would be:
Basic command mode/editing mode toggling:
i Insert before cursor
Esc Toggle to command modeCursor motion keys:
h Move left
j Move down
k Move up
l Move rightw Move to next word
b Move to the beginning of the word0 Move to the beginning of the line
$ Move to the end of the lineAnd delete/change:
x delete next character to the right
d{motion} delete amount specified by…
11 votes
- Don't see your idea?