Is the output of MongoDB a JSON object or a document?

The collection in MongoDB can be exported to a JSON file using the mongoexport parameter.

Solution 1:

Here’s the actual answer:

To transform a mongo object into a JSON object, simply utilize the utility method present in every mongo object, as shown in



By executing


on the response object, you can easily perform the desired action.


Products.findById(id).then(res => {
    const jsonRes = res.toJSON();
    // Here jsonRes is JSON

You have the option of obtaining the JSON object directly through the utilization of



Products.findById(id).lean().then(res => {
    // Here res is JSON

Solution 2:

To achieve the task, it is necessary to change the object id to a string format.

var result = {
  "_id": ObjectId("5739a6bf3f1b41477570dc89"),
  "taskCount": 2,
  "study": "cod"
//now convert to string 
//now you can use the result

Solution 3:

Try this,

var cursor =db.collection('rhimeReport').find(

Hope this help.

Frequently Asked Questions