How to get valid JSON output with Mongosh version 1.10.5?
Below is my mongosh query to get my desired results, I believe it is coming in BJSON(Binary JSON) format on which I'm unable to use jq tool for filtering the desired key: value pairs.
mongosh "mongodb+srv://testuser:[email protected]/testdb?retryWrites=true&w=majority" --quiet --eval 'db.testcheck.find({ "submittedAt": { $gt: ISODate("2023-10-06T00:00:00.000Z") }, "email": { $not: { $regex: /@(example\.com|example\.ai)$/i } } })'
So how do I modify it to get the desired JSON format output and not BJSON format?
I tried the below command using this https://www.mongodb.com/community/forums/t/mongosh-json-output/116389/4 link but throwing TypeError: EJSON.stringfy is not a function
mongosh "mongodb+srv://testuser:[email protected]/testdb?retryWrites=true&w=majority" --quiet --eval 'EJSON.stringfy(db.testcheck.find({ "submittedAt": { $gt: ISODate("2023-10-06T00:00:00.000Z") }, "email": { $not: { $regex: /@(example\.com|example\.ai)$/i } } }))'
Error-Message
-------------
TypeError: EJSON.stringfy is not a function
How can I get the desired JSON format output and not BJSON format using mongosh for above query?