问题描述:如何根据_id查询出该条记录 并删除该条记录judge数组中 满足 id==“111111” 的数据。
{
_id:"all",
judge:[
{"index":0,id:"111111"},
{"index":1,id:"222222"},
{"index":0,id:"111111"},
{"index":1,id:"333333"},
]
}
注意删除的是 该条数据中数组中的数据。
网友回复
stop eating:
const db = wx.cloud.database();
const _ = db.command;
db.collection("code")
.where({
_id: '35af80fb5f3b54440000a04857d3c063'
})
.update({
data: {
judge: _.pull({
id: _.eq("111111")
})
}
})
?:
写个循环 在循环里
let tempArr = judge;
tempArr.forEach((item,index)=>{
if(item.id=='111111'){
tempArr.splice(index,1)
}
})
judge = tempArr;