Mongoose schemaType's get: method, when fetching data, the method does not work.

the domain.js code is as follows

var mongoose = require("mongoose")
var moment = require("moment")
var Schema = mongoose.Schema
function dateformat(val) {
    console.log("dateformat" + val);//

    return moment(val).format("YYYY-MM-DD");
}
var schema = new Schema({
    id: Number,
    domain: String,
    title: {
        type: String
    },
    keyword: String,
    describe: String,
    date: {
        type: Date,
        default: Date.now,
        get: dateformat //get,dateformat(),
    }
})
module.exports = schema

the express.js code is as follows

var express = require("express");
var domains = require("../../models/domains")//models ,schemadomain.js
var router = express.Router();
var info = {}
router.get("/domain", async (req, res) => {
  var domaindb
  where = {}
  domaindb = domains.findOne(where).exec()
  domaindb = await domaindb
  
  console.log(domaindb)//domaindb,date,.
  if (domaindb) {
    info.code = 0
    info.message = domaindb
  } else {
    info.code = -1
    info.message = ""
  }
  return res.json(info);
});
Mar.10,2021

has found a solution. Thank you
and finally change it to this

.
date: {
    type: Date,
    default: Date.now,
    get(val){
        return moment(val).format('YYYY-MM-DD HH:mm:ss');
    }
}

be sure to write this sentence. Only when transferring to JSON can you call the get method
schema.set ('toJSON', {getters: true});

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-1b3a2ff-2b73e.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-1b3a2ff-2b73e.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?