我有一个数据库db2,其中名为‘’user‘’的结构如下,其中cangku为json对象数组:
[
{
account:"zzl",
password:"zzl",
cangku:[
{
code: "001"
name: "可乐"
price: "3"
type: "瓶装"
_createTime: "1.654630149e+12"
_updateTime: ""
},
{
code: "002"
name: "米"
price: "11"
type: ""
_createTime: "1.656666751e+12"
_updateTime: ""
},
]
},
{
account:"user2",
password:"user2",
cangku:[
{
code: "004"
name: "水"
price: "3"
type: "瓶装"
_createTime: "1.654630149e+12"
_updateTime: ""
},
{
code: "005"
name: "玩具"
price: "11"
type: ""
_createTime: "1.656666751e+12"
_updateTime: ""
},
]
}
]
我使用如下代码
const db2 = wx.cloud.database().collection('user')
db2.where({
account:zzl,
password:zzl,
'cangku.code':123
// cangku:{
// code:123
// }
}).get({
success: function(res) {
console.log(res.data)
}
})
输出结果如下
{
account:"zzl",
password:"zzl",
cangku:[
{
code: "001"
name: "可乐"
price: "3"
type: "瓶装"
_createTime: "1.654630149e+12"
_updateTime: ""
},
{
code: "002"
name: "米"
price: "11"
type: ""
_createTime: "1.656666751e+12"
_updateTime: ""
},
]
}
请问如何只输出满足account和password以外,code为001的如下数据,即只输出满足code=001的同级数据
{
code: "001"
name: "可乐"
price: "3"
type: "瓶装"
_createTime: "1.654630149e+12"
_updateTime: ""
}
还有如何知道where找到的数据的索引位置,有没有可能在不去单独取出这个json数据的前提下,对该json数据的cangku的特定商品的数据进行增删改查
只能聚合