-1
我訂閱了該作業,並且偵聽到了新消息,我得到了一個與MongoDB的ObjectId類似的ID。 當我使用本機MongoDB驅動程序時,一切正常,但是當我嘗試使用Mongoose時出現此錯誤:findOne
方法返回隊列中的先前值。使用mongodb和rabbitmq處理任務
我的嘗試:
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);