Can getter setter methods in Mongoose access attributes of the document itself? For instance could their behavior depend on whether the content is supposed to be compressed or not. Here I'm just making up this guessing that it might be bound to the document, but I can't readily see docs to this effect:
function compress(val) {
if (this.compressed) return zlib.gzipSync(val);
else return val;
}
function expand(val) {
if (this.compressed) return zlib.gunzipSync(val);
else return val;
}
var MyObject = new mongoose.Schema({
content: {type: mongoose.Schema.Types.Mixed, set: compress, get: expand},
compressed: {type: Boolean, required: true, default: false}
});