![](/img/trans.png)
[英]Use findOneAndUpdate $pull and populate does not update or Populate
[英]findOneAndUpdate does not update document
我有以下方法來更新我的文檔:
const findAndDisabledAlert = id => (
AlertModel.findOneAndUpdate({ _id: id }, { $set: { status: 'D' } }, { new: true }, (err, alt) => {
if (err) console.log(err);
return alt;
})
);
但這不會更新文檔並返回null,我也嘗試了不使用“ $ set”但得到相同的結果。
以下測試將創建警報,但不會更改狀態:
test('Should create, find and disable an alert', async () => {
const currencyAlert = {
name: 'VTC',
pair: 'BTC',
price: 0.00009241,
condition: 'H',
status: 'D',
exchange: 'BITTREX',
};
const alert = await createAlert(currencyAlert);
const alertDisabled = await findAndDisabledAlert(alert.id);
expect(alertDisabled.status).toBe('D');
});
語句const alertDisabled =等待findAndDisabledAlert(alert.id); 不
const alertDisabled = await findAndDisabledAlert(alert._id);
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.