Does console.log call the toObject method of the mongoose document?

const mongoose = require("mongoose")
mongoose.connect("mongodb://localhost/test")
const A = mongoose.model("A", new mongoose.Schema({name: String}))

A.create({name: "aaa"}, (err, doc) => {
  console.log(doc) // { _id: 5ae424bdcc21a02b700f9342, name: "aaa", __v: 0 }
  doc.toObject = o => 0
  console.log(doc) // 0
})
// ------------------------------------
A.create({name: "aaa"}, (err, doc) => {
  console.log(doc) // { _id: 5ae42509ae09661d681416f8, name: "aaa", __v: 0 }
  doc.toObject = 0
  console.log(doc) // : TypeError: this.toObject is not a function
})

is a call to toString .

Document.prototype.inspect = function(options) {
  var isPOJO = options &&
    utils.getFunctionName(options.constructor) === 'Object';
  var opts;
  if (isPOJO) {
    opts = options;
    opts.minimize = false;
  }
  return this.toObject(opts);
};

/**
 * Helper for console.log
 *
 * @api public
 * @method toString
 * @memberOf Document
 */

Document.prototype.toString = function() {
  return inspect(this.inspect());
};
MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1b39511-2c19e.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1b39511-2c19e.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?