Reputation: 3
i try to wirte a js script to pull an elem in a array in mongo.
// this one not work, which return "{ ok: 1, nModified: 0, n: 1 }"
db.userModel.updateOne({"_id":userId}, {"$pull" : {"draw.awardList":{oldActiveCode : oldTime}}}, function(err, res) ..
// this one work,
db.userModel.updateOne({"_id":userId}, {"$pull" : {"draw.awardList":{"1000812001401": 1553503004448}}}, function(err, res)
// but when i compare then, it seems equal
console.log("+++",("1000812001401" === oldActiveCode), (oldTime === 1553503004448))
output : +++ true true
Upvotes: 0
Views: 35
Reputation: 222750
{oldActiveCode : oldTime}
and {"1000812001401": 1553503004448}
are not the same. The former sets oldActiveCode
property, and the latter sets 1000812001401
property.
If the property should be 1000812001401
, it should be computed property, {[oldActiveCode] : oldTime}
.
Upvotes: 1