提交 864aefc5 编写于 作者: 雪洛's avatar 雪洛

Update cf-database.md

上级 e9cfba14
...@@ -348,7 +348,7 @@ collection.field({ 'age': true }) ...@@ -348,7 +348,7 @@ collection.field({ 'age': true })
比如筛选出所有自己发表的文章,除了用传对象的方式: 比如筛选出所有自己发表的文章,除了用传对象的方式:
```js ```js
const myOpenID = 'xxx' const myOpenID = "xxx"
db.collection('articles').where({ db.collection('articles').where({
_openid: myOpenID _openid: myOpenID
}) })
...@@ -358,7 +358,7 @@ db.collection('articles').where({ ...@@ -358,7 +358,7 @@ db.collection('articles').where({
```js ```js
const dbCmd = db.command const dbCmd = db.command
const myOpenID = 'xxx' const myOpenID = "xxx"
db.collection('articles').where({ db.collection('articles').where({
_openid: dbCmd.eq(openid) _openid: dbCmd.eq(openid)
}) })
...@@ -604,25 +604,46 @@ collection.doc('doc-id').update({ ...@@ -604,25 +604,46 @@ collection.doc('doc-id').update({
``` ```
// 更新前 // 更新前
{ {
_id: 'xxx', "_id": "xxx",
name: "Hello", "name": "Hello",
count: { "count": {
fav: 0, "fav": 0,
follow: 0 "follow": 0
} }
} }
// 更新后 // 更新后
{ {
_id: 'xxx', "_id": "xxx",
name: "Hey", "name": "Hey",
count: { "count": {
fav: 1, "fav": 1,
follow: 0 "follow": 0
} }
} }
``` ```
更新数组时,已数组下标作为key即可,比如以下示例将数组arr内下标为1的值修改为 uniCloud
```
collection.doc('doc-id').update({
arr: {
1: "uniCloud"
}
})
```
```
// 更新前
{
"arr": ["hello", "world"]
}
// 更新后
{
"arr": ["hello", "uniCloud"]
}
```
### 更新文档,如果不存在则创建 ### 更新文档,如果不存在则创建
collection.doc().set() collection.doc().set()
...@@ -645,20 +666,20 @@ collection.doc('doc-id').set({ ...@@ -645,20 +666,20 @@ collection.doc('doc-id').set({
``` ```
// 更新前 // 更新前
{ {
_id: 'xxx', "_id": "xxx",
name: "Hello", "name": "Hello",
count: { "count": {
fav: 0, "fav": 0,
follow: 0 "follow": 0
} }
} }
// 更新后 // 更新后
{ {
_id: 'xxx', "_id": "xxx",
name: "Hey", "name": "Hey",
count: { "count": {
fav: 1 "fav": 1
} }
} }
``` ```
...@@ -697,21 +718,21 @@ db.collection('photo').doc('doc-id').update({ ...@@ -697,21 +718,21 @@ db.collection('photo').doc('doc-id').update({
``` ```
// 更新前 // 更新前
{ {
_id: 'xxx', "_id": "xxx",
name: "Hello", "name": "Hello",
count: { "count": {
fav: 0, "fav": 0,
follow: 0 "follow": 0
} }
} }
// 更新后 // 更新后
{ {
_id: 'xxx', "_id": "xxx",
name: "Hello", "name": "Hello",
count: { "count": {
fav: 1, "fav": 1,
follow: 1 "follow": 1
} }
} }
``` ```
...@@ -744,21 +765,21 @@ db.collection('user').where({ ...@@ -744,21 +765,21 @@ db.collection('user').where({
``` ```
// 更新前 // 更新前
{ {
_id: 'xxx', "_id": "xxx",
name: "Hello", "name": "Hello",
count: { "count": {
fav: 0, "fav": 0,
follow: 0 "follow": 0
} }
} }
// 更新后 // 更新后
{ {
_id: 'xxx', "_id": "xxx",
name: "Hello", "name": "Hello",
count: { "count": {
fav: 1, "fav": 1,
follow: 0 "follow": 0
} }
} }
``` ```
...@@ -786,21 +807,21 @@ db.collection('user').where({ ...@@ -786,21 +807,21 @@ db.collection('user').where({
``` ```
// 更新前 // 更新前
{ {
_id: 'xxx', "_id": "xxx",
name: "Hello", "name": "Hello",
count: { "count": {
fav: 2, "fav": 2,
follow: 0 "follow": 0
} }
} }
// 更新后 // 更新后
{ {
_id: 'xxx', "_id": "xxx",
name: "Hello", "name": "Hello",
count: { "count": {
fav: 20, "fav": 20,
follow: 0 "follow": 0
} }
} }
``` ```
...@@ -822,15 +843,15 @@ db.collection('comments').doc('comment-id').update({ ...@@ -822,15 +843,15 @@ db.collection('comments').doc('comment-id').update({
``` ```
// 更新前 // 更新前
{ {
_id: 'xxx', "_id": "xxx",
rating: 5, "rating": 5,
comment: 'xxxx' "comment": "xxx"
} }
// 更新后 // 更新后
{ {
_id: 'xxx', "_id": "xxx",
comment: 'xxxx' "comment": "xxx"
} }
``` ```
...@@ -852,14 +873,14 @@ db.collection('comments').doc('comment-id').update({ ...@@ -852,14 +873,14 @@ db.collection('comments').doc('comment-id').update({
``` ```
// 更新前 // 更新前
{ {
_id: 'xxx', "_id": "xxx",
users: ['a','b'] "users": ["a","b"]
} }
// 更新后 // 更新后
{ {
_id: 'xxx', "_id": "xxx",
users: ['a','b','c','d'] "users": ["a","b","c","d"]
} }
``` ```
...@@ -879,14 +900,14 @@ db.collection('comments').doc('comment-id').update({ ...@@ -879,14 +900,14 @@ db.collection('comments').doc('comment-id').update({
``` ```
// 更新前 // 更新前
{ {
_id: 'xxx', "_id": "xxx",
users: ['a','b'] "users": ["a","b"]
} }
// 更新后 // 更新后
{ {
_id: 'xxx', "_id": "xxx",
users: ['a'] "users": ["a"]
} }
``` ```
...@@ -908,14 +929,14 @@ db.collection('comments').doc('comment-id').update({ ...@@ -908,14 +929,14 @@ db.collection('comments').doc('comment-id').update({
``` ```
// 更新前 // 更新前
{ {
_id: 'xxx', "_id": "xxx",
users: ['a','b'] "users": ["a","b"]
} }
// 更新后 // 更新后
{ {
_id: 'xxx', "_id": "xxx",
users: ['c','d','a','b'] "users": ["c","d","a","b"]
} }
``` ```
...@@ -935,14 +956,14 @@ db.collection('comments').doc('comment-id').update({ ...@@ -935,14 +956,14 @@ db.collection('comments').doc('comment-id').update({
``` ```
// 更新前 // 更新前
{ {
_id: 'xxx', "_id": "xxx",
users: ['a','b'] "users": ["a","b"]
} }
// 更新后 // 更新后
{ {
_id: 'xxx', "_id": "xxx",
users: ['b'] "users": ["b"]
} }
``` ```
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册