在post find mongoose hook中修改结果

时间:2015-07-26 17:12:00

标签: node.js mongodb mongoose mongoose-populate

我试图找到一种方法来修改mongoose的查询结果。

下面是带有post hook的自包含模型

'use strict';

// load the things we need
var mongoose = require('mongoose');
var invoice_db = mongoose.createConnection(config.mongo.url + '/invoiceDB'); //connect to buyer DB
var path = require('path');


// define the schema for our invoice details model
var invoicedetailSchema = new Schema({
    //SCHEMA INFO
});

invoicedetailSchema.post('find', function(results){

console.log('POST FIRED')

    results = results.filter(function(doc){
     return doc.tags.length;
   })
})

var InvoiceModel = invoice_db.model('InvoiceDetail', invoicedetailSchema);


// create the model for seller and expose it to our app
promise.promisifyAll(InvoiceModel);
promise.promisifyAll(InvoiceModel.prototype);
module.exports = InvoiceModel;

查找查询工作正常并且帖子正在触发,但结果不会根据帖子钩子进行过滤。

如何在返回结果之前编辑结果。

0 个答案:

没有答案
相关问题