db.dbDB.collection("buy").updateMany(
{
$and: [
{ profit: { $eq: null } },
{ tp_buy: { $gte: incomingData.bid } },
],
},
{
$set: {
profit: true,
execute_p: incomingData.bid,
},
}
);
我有這個updateMany()功能。
{
"_id" : ObjectId("asdfeasd"),
"profit" : true,
"tp_buy" : 1.16583,
"execute_p" : 1.16487
}
但是,正如它顯示的那樣,即使我的資料庫incomingData.bid沒有超過tp_buy.
之前,修改profit,它被賦值為null。
Console.loggingincomingData.bid回傳number并在 MongoDB 上tp_buy宣告double。
如何僅在檔案具有profit值null且incomingData.bid大于時更新tp_buy?
uj5u.com熱心網友回復:
詢問
- 我認為你的比較錯誤,如果可以的話試試這個
- 而不是
1.2把incomingData.bid incomingData.bid > tp_buy就好像tp_buy< incomingData.bid
測驗代碼在這里
db.collection.update({
$and: [
{
profit: {
$eq: null
}
},
{
tp_buy: {
$lt: 1.2
}
},
],
},
{
$set: {
profit: true,
execute_p: 1.2,
},
})
轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/329200.html
下一篇:向現有資料添加額外級別的嵌套?
