mongoose static methods not showing model document in console

Viewed 11

I have a database of jobs, I am trying to create a mongoose static method to toggle a field on specific jobs to true or false. I have been trying to figure out mongoose methods and have hit a road block just trying to console.log a document to screen. I am just trying to use this.find to get a document from my mongo db whenever I run the static method but it seems to not work.

Model

const mongoose = require('mongoose');
const proxyModel = require('./proxyModel');
const User = require('./userModel');


const pendingJobModel = new mongoose.Schema({
    date:{type:String, required: true, unique:true},
    startTime:{type:String, required: true},
    endTime:{type:String, required: true},
    courseList:{type:[String], required: true},
    member:{type:String},
    clubUsername:{type:String, required: true},
    clubPassword:{type:String, required: true},
    proxy:{type:Boolean, required: true, default:false},
    active:{type:Boolean, required: true, default:false},
},{collection:'pendingjobs'})

// pendingJobModel.statics.findByIdAndToggleActive = function(id, callback){
//     this.find({_id:id}, callback)
//     console.log('tried')
// }

pendingJobModel.static('findByID', function(id){
    this.find({_id:id}, function(err, resp){
        if(err){
            console.log(err)
        }else{
            console.log(resp)
        }
    })
    
})
module.exports = mongoose.model('PendingJob', pendingJobModel)

Calling static method

async function startBot(){ 
console.log("[+] Bot Starting...")
const callback = function(err, resp){
    if(err){
        console.log(err)
    }else{
        console.log(resp)
    }
}
PendingJob.findByID('63169a53a8944fd098f3d88b')

Why cant I see my document in console when I run the model static method??

0 Answers
Related