提交 7814f963 编写于 作者: 雪洛's avatar 雪洛

docs: db arr update

上级 5b3b173f
......@@ -830,6 +830,90 @@ let res = await collection.where({name: dbCmd.eq('hey')}).update({
})
```
### 更新数组内指定下标的元素
```js
const res = await db.collection('query').doc('1').update({
// 更新students[1]
['students.' + 1]: {
name: 'wang'
}
})
```
```js
// 更新前
{
"_id": "1",
"students": [
{
"name": "zhang"
},
{
"name": "li"
}
]
}
// 更新后
{
"_id": "1",
"students": [
{
"name": "zhang"
},
{
"name": "wang"
}
]
}
```
### 更新数组内匹配条件的元素
```js
const res = await db.collection('query').where({
'students.name': 'wang'
}).update({
// 将students内第一个name为wang的name改为li
'students.$.name': 'li'
})
```
```js
// 更新前
{
"_id": "1",
"students": [
{
"name": "zhang"
},
{
"name": "wang"
},
{
"name": "wang"
}
]
}
// 更新后
{
"_id": "1",
"students": [
{
"name": "zhang"
},
{
"name": "li"
},
{
"name": "wang"
}
]
}
```
### 更新操作符
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册