我想运行更新并为每个更新的资源发布消息。它作为带回调的标准mongoose查询运行时工作正常,但即使将资源输出到流中,也无法使用流产生效果。
var discount = {
startDate: process.env.START_DATE,
endDate: process.env.END_DATE,
funding: process.env.FUNDING,
percentage: process.env.PERCENTAGE
}
var connection = mongoose.createConnection(mongoEndpoint, config.mongo);
var Resources = connection.model('Resources', resourcesSchema);
var stream = Resources.update({_id:6375668}, { $push: { discounts: 'blob2' } }, { multi: true });
stream.on('data', function(resource) {
console.log('Updated resource + published message',resource._id, discount)
rabbit.publish('index-resource', resource);
});
stream.on('end', function() {
console.log('Updated all resources in query');
process.exit(0);
})
var ResourceSchema = module.exports = new Schema({
_id: Number,
discounts: Array
}, {versionKey: false});
答案 0 :(得分:0)
看起来您的resourcesSchema在这里未定义了吗?
var Resources = connection.model('Resources', resourcesSchema);