【发布时间】:2016-03-02 17:14:44
【问题描述】:
我订阅了这份工作,并收听了新消息,我得到了一个类似于 MongoDB 的 ObjectId 的 ID。
当我使用本机 MongoDB 驱动程序时,一切正常,但是当我尝试使用 Mongoose 时出现此错误:findOne 方法从队列中返回了先前的值。
我尝试了什么:
q.subscribe((message, headers, deliveryInfo, ack) => {
const workerId = message.workerId; // everytime changed, it`s ok!
MongoClient.connect(url, (err, db) => {
const collection = db.collection('workers');
collection.findOne({_id: workerId}, (err, item) => {
logger.info('native ', item); // return actual data by id
});
});
Workers.findOne(workerId, (err, item) => {
logger.info('mongoose ', item); // return previos value! why??? workerId changed it other values, because it another job
});
});
所以,猫鼬在我没有运行时返回了旧对象
ack.acknowledge(true);
【问题讨论】: