Uploaded image for project: 'Documentation'
  1. Documentation
  2. DOCS-16238

How to get a MongoDB Shell find query output printed in one line

    XMLWordPrintableJSON

Details

    • Icon: Task Task
    • Resolution: Won't Do
    • Icon: Minor - P4 Minor - P4
    • Server_Docs_20231030
    • None
    • mongosh
    • None
    • MongoDB Shell

    Description

      By default, the MongoDB Shell output for find queries is printed in the following way:

       

      {
      "id": 1,
      "name": "John"
      }

       

      In order to get a MongoDB Shell find query output printed in one line you may use one of the following options:

      Example:

      { "id": 1, "name": "John" }

      1. Run the following command:

      db.coll.find().forEach((doc) => print(util.inspect(doc, { compact: Infinity, breakLength: Infinity })))

      2. If you are using programmatic parsing, you might find it useful to use the EJSON(Extended JSON):

      EJSON.stringify(db.coll.find().toArray())

      Attachments

        Activity

          People

            Unassigned Unassigned
            anastasia.kravtsov@mongodb.com Anastasia Kravtsov
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:
              31 weeks, 5 days ago