[DOCS-16238] How to get a MongoDB Shell find query output printed in one line Created: 30/Jun/23  Updated: 30/Oct/23  Resolved: 30/Jun/23

Status: Closed
Project: Documentation
Component/s: mongosh
Affects Version/s: None
Fix Version/s: Server_Docs_20231030

Type: Task Priority: Minor - P4
Reporter: Anastasia Kravtsov Assignee: Unassigned
Resolution: Won't Do Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified
Environment:

MongoDB Shell


Participants:
Days since reply: 31 weeks, 5 days ago

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



 Comments   
Comment by Anastasia Kravtsov [ 30/Jun/23 ]

opened wrongly by mistake

Generated at Thu Feb 08 08:14:55 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.