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.

1 result found

  1. 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 votes

    We're glad you're here

    Please sign in to leave feedback

    Signed in as (Sign out)

    We’ll send you updates on this idea

    0 comments  ·  Scripting  ·  Admin →

    Starting 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)`.

  • Don't see your idea?

MongoDB Shell

Categories

Feedback and Knowledge Base