Skip to content

MongoDB Shell

The MongoDB Shell (mongosh) lets you connect to MongoDB to work with your data and configure your database.

Help us improve the MongoDB Shell by posting your ideas and suggestions for improvements.

To report bugs, please use our MONGOSH JIRA project.

6 results found

  1. The new mongosh mangles the output of piped in commands

    With the old mongo shell, you could set up a shell file (called something like mongo_cmd.sh)containing the path to the executable and all the command line switches you wanted like this:

    /path/to/mongo --norc --quiet --port 26011

    and then in your other script files pipe commands into an invocation of mongocmd.sh like the following:
    ```
    CMD
    FILE=./mongo_cmd.sh

    STATS=$(echo 'db.stats().ok' | $CMDFILE)
    DBVERSION=$(echo 'db.version()' | $CMD
    FILE)

    echo "db.stats().ok output:" $STATS
    echo "db.version() output:" $DBVERSION
    ```

    and the output would be this:

    db.stats().ok output: 1
    db.version() output: 6.0.5

    But if you replace mongo with the new shell mongosh in the…

    2 votes
    1 comment  ·  Scripting  ·  Admin →
    How important is this to you?
  2. Better mongo file loading performance

    Manage a faster loading of files in command line to have better perfs for multiple small scripts.

    See Case 01251177.

    1 vote
    0 comments  ·  Scripting  ·  Admin →
    How important is this to you?
  3. mongosh parse mongo url offline

    In scripting easiers and most robust way to pass mongodb connection info using url string. Sometimes though there is need to parse part of it, like database name or specific query params. In NodeJS whathg URL can be used for this, additionally validating url. For mongsh only way at the moment is to perform actual connecion to running mongodb:

    mongosh "mongodb://127.0.0.1:27017/staging?serverSelectionTimeoutMS=15000&readPreference=secondaryPreferred" --quiet -eval "print(db)"
    staging_db

    Would be nice if mongosh can be used to parse mongodb URL and output some part of it wihtout need for actual connection. This use case if for bash scripting, currently working on combination of…

    1 vote
    0 comments  ·  Scripting  ·  Admin →
    How important is this to you?
  4. add _prettyShell=false to mongosh

    In 4.4, the mongo shell prints 'ugly' by default. Many of our scripts are written to expect this type of output. The mongo shell includes the command: DBQuery.prototype._prettyShell=false to explicitly set this. In mongosh, there is no built in/native ability to achieve the same output as mongo shell.

    1 vote
    0 comments  ·  Scripting  ·  Admin →
    How important is this to you?
  5. Change mongosh to process and use arguments only up to a "--" sentinel

    Getting command line arguments into mongosh is virtually impossible.  The --eval option insists on printing the last eval expr evaluated to the console despite the --quiet switch.  Allowing a script to self parse and manage any args following the "–" sentinel using the "process.argv" array would permit the developer a wide array of choices in handling script input from a command line.

    " > mongosh mongo-options script file – arg arg... "

    Component: mongosh

    Versions: 1.4.x and up

    1 vote
    4 comments  ·  Scripting  ·  Admin →
    How important is this to you?
  6. Suggest new feature for loading scripts: loadScript and loadFolder

    For loading external script into MongoSh current session, currently we have the load() function, which is enough for the task. But I found myself using my own functions instead. So I would like to describe those as suggestion to improve MongoSh:

    loadScript()

    This function is basically has the same function with load(). But has 1 major difference: all relative paths in the script has the same base directory with the script itself, not the current MongoSh working directory.
    For example:
    - Script "D:\MyProject\src\script.js" have these references: "test.js", "../test2.js"
    - Current working dir process.cwd(): "C:\MongoSh"
    - Path resolved…

    1 vote
    0 comments  ·  Scripting  ·  Admin →
    How important is this to you?
  • Don't see your idea?

MongoDB Shell

Categories

Feedback and Knowledge Base