Q:

How to return an error in a mongoose query method?

I am just getting started with mongoose query methods they are really cool. I made a query method for knowing the ownership of an object. If yes it is his own, then the value of the object will be displayed else it should do an error like returning some error instead of something else.
someSchema.query.isOwner = function(user) {
    if (user.admin)
        return this;
    /* I know this will not work please suggesta solution for this too */
    else if (user._id === iShouldbeAbleToAccessTheObjectHere._id)
        return this;
    else
        // Put this into the error of exec
        return new Error('Permission denied!');
};

// This is how I'll use it
SomeModel
    .findById(someId)
    .isOwner(currentUser)
    .exec((err, result) => {
      if (err)
        res.json({ error : err });
      res.json({ data : result });
    });

A:

//model.js
var ObjectId = require('mongoose').Types.ObjectId; 
var someModel = new mongoose.model('somemodel',someSchema);

someModel.findByIdAndCheckOwnership = function(id, callback){

    this.find({ _id :  new ObjectId(id), admin : true}, function(err, user){
        if(err){
            callback('Your Custom Error Msg', null);
        }
        else{
            callback(null, user);
        }
    });
}

//use of model in some other.js
SomeModel.findByIdAndCheckOwnership(id, function(err, user){

    if(err){
        res.json({ error :err });
    }
    else{
        res.json({ user : user });
    }
});

//populate
someModel.findByIdAndCheckOwnership = function(id, callback){

    this.find({ _id :  new ObjectId(id), admin : true}).populate('your_population_fields').exec(function(err, user){
        if(err){
            callback('Your Custom Error Msg', null);
        }
        else{
            callback(null, user);
        }
    });
}

