Tag: 设置器

为什么我的Mongoose 3.8.7模式获取器和设置器被忽略?

在使用Node.js,Mongoose和MongoDB时,我发现当执行findOne查询时,我的Mongoose模式获取器和设置器不会触发。 我发现了一个旧的线程,表明在版本2.x中有一个getter和setter的问题,但是它表明它已经被解决了,而且我正在使用最新版本的Mongoose(3.8.7)。 这是我的模式的一部分 function testGetter(value) { return value + " test"; } /** * Schema */ var schema = new Schema({ username: { type: String, required: true, unique: true, get: testGetter } }); // I have also tried this. schema.path('username').get(function (value, schemaType) { return value + " test"; }); 以下是我如何执行查询 Model .findOne(conditions, fields, options) .populate(population) […]