The following previous answer partially solved what I wanted to achieve.
I’m pulling data out of a mongo instance running in a kubernettes cluster (and can’t connect using a GUI like Compass). Compass has a view of the data that converts the document to JSON. Using EJSON.stringify and the toArray() method almost gives the output I was hoping for. I’m totally new to mongo and have some follow up questions.
Is there a way to output the EJSON.stringify format on queries once already running the mongosh? For my purposes the “pretty” output isn’t really useful as I (ideally) want to be able to copy and paste output.
The output of the eval is mostly great but I’ve noticed that certain fields lose their data type descriptors. For example in my database we have some integers defined as Long. The current output of the EJSON.stringify for these fields is { "myLong": 12345 } whereas I was hoping for something more like "myLong": { "$numberLong": "12345" } which more closely matches the Compass output. Is there a way to retain this detail? The saved output will form part of a test that will inject this data back into an empty db so I’d like it as close to reality as possible.
Thanks in advance, happy to be pointed to docs I may have missed. Still learning.
Is there a way to output the EJSON.stringify format on queries once already running the mongosh? For
You can use EJSON.stringify() in the regular mongosh prompt as well on the result of .toArray(), e.g. EJSON.stringify(db.test.find().toArray(), null, 2) is totally fine.
but I’ve noticed that certain fields lose their data type descriptors