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

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

    • Type: Icon: Task Task
    • Resolution: Won't Do
    • Priority: Icon: Minor - P4 Minor - P4
    • Server_Docs_20231030
    • Affects Version/s: None
    • Component/s: mongosh
    • Labels:
      None
    • Environment:
      MongoDB Shell

      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())

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

              Created:
              Updated:
              Resolved:
              43 weeks, 4 days ago