diff --git a/docs/uniCloud/cf-database.md b/docs/uniCloud/cf-database.md index e7068237f7c785edff9a194b6c0832450b62d07f..78d9ad410cb90256d4596ad5250cada1ce004255 100644 --- a/docs/uniCloud/cf-database.md +++ b/docs/uniCloud/cf-database.md @@ -348,7 +348,7 @@ collection.field({ 'age': true }) 比如筛选出所有自己发表的文章,除了用传对象的方式: ```js -const myOpenID = 'xxx' +const myOpenID = "xxx" db.collection('articles').where({ _openid: myOpenID }) @@ -358,7 +358,7 @@ db.collection('articles').where({ ```js const dbCmd = db.command -const myOpenID = 'xxx' +const myOpenID = "xxx" db.collection('articles').where({ _openid: dbCmd.eq(openid) }) @@ -604,25 +604,46 @@ collection.doc('doc-id').update({ ``` // 更新前 { - _id: 'xxx', - name: "Hello", - count: { - fav: 0, - follow: 0 + "_id": "xxx", + "name": "Hello", + "count": { + "fav": 0, + "follow": 0 } } // 更新后 { - _id: 'xxx', - name: "Hey", - count: { - fav: 1, - follow: 0 + "_id": "xxx", + "name": "Hey", + "count": { + "fav": 1, + "follow": 0 } } ``` +更新数组时,已数组下标作为key即可,比如以下示例将数组arr内下标为1的值修改为 uniCloud + +``` +collection.doc('doc-id').update({ + arr: { + 1: "uniCloud" + } +}) +``` + +``` +// 更新前 +{ + "arr": ["hello", "world"] +} +// 更新后 +{ + "arr": ["hello", "uniCloud"] +} +``` + ### 更新文档,如果不存在则创建 collection.doc().set() @@ -645,20 +666,20 @@ collection.doc('doc-id').set({ ``` // 更新前 { - _id: 'xxx', - name: "Hello", - count: { - fav: 0, - follow: 0 + "_id": "xxx", + "name": "Hello", + "count": { + "fav": 0, + "follow": 0 } } // 更新后 { - _id: 'xxx', - name: "Hey", - count: { - fav: 1 + "_id": "xxx", + "name": "Hey", + "count": { + "fav": 1 } } ``` @@ -697,21 +718,21 @@ db.collection('photo').doc('doc-id').update({ ``` // 更新前 { - _id: 'xxx', - name: "Hello", - count: { - fav: 0, - follow: 0 + "_id": "xxx", + "name": "Hello", + "count": { + "fav": 0, + "follow": 0 } } // 更新后 { - _id: 'xxx', - name: "Hello", - count: { - fav: 1, - follow: 1 + "_id": "xxx", + "name": "Hello", + "count": { + "fav": 1, + "follow": 1 } } ``` @@ -744,21 +765,21 @@ db.collection('user').where({ ``` // 更新前 { - _id: 'xxx', - name: "Hello", - count: { - fav: 0, - follow: 0 + "_id": "xxx", + "name": "Hello", + "count": { + "fav": 0, + "follow": 0 } } // 更新后 { - _id: 'xxx', - name: "Hello", - count: { - fav: 1, - follow: 0 + "_id": "xxx", + "name": "Hello", + "count": { + "fav": 1, + "follow": 0 } } ``` @@ -786,21 +807,21 @@ db.collection('user').where({ ``` // 更新前 { - _id: 'xxx', - name: "Hello", - count: { - fav: 2, - follow: 0 + "_id": "xxx", + "name": "Hello", + "count": { + "fav": 2, + "follow": 0 } } // 更新后 { - _id: 'xxx', - name: "Hello", - count: { - fav: 20, - follow: 0 + "_id": "xxx", + "name": "Hello", + "count": { + "fav": 20, + "follow": 0 } } ``` @@ -822,15 +843,15 @@ db.collection('comments').doc('comment-id').update({ ``` // 更新前 { - _id: 'xxx', - rating: 5, - comment: 'xxxx' + "_id": "xxx", + "rating": 5, + "comment": "xxx" } // 更新后 { - _id: 'xxx', - comment: 'xxxx' + "_id": "xxx", + "comment": "xxx" } ``` @@ -852,14 +873,14 @@ db.collection('comments').doc('comment-id').update({ ``` // 更新前 { - _id: 'xxx', - users: ['a','b'] + "_id": "xxx", + "users": ["a","b"] } // 更新后 { - _id: 'xxx', - users: ['a','b','c','d'] + "_id": "xxx", + "users": ["a","b","c","d"] } ``` @@ -879,14 +900,14 @@ db.collection('comments').doc('comment-id').update({ ``` // 更新前 { - _id: 'xxx', - users: ['a','b'] + "_id": "xxx", + "users": ["a","b"] } // 更新后 { - _id: 'xxx', - users: ['a'] + "_id": "xxx", + "users": ["a"] } ``` @@ -908,14 +929,14 @@ db.collection('comments').doc('comment-id').update({ ``` // 更新前 { - _id: 'xxx', - users: ['a','b'] + "_id": "xxx", + "users": ["a","b"] } // 更新后 { - _id: 'xxx', - users: ['c','d','a','b'] + "_id": "xxx", + "users": ["c","d","a","b"] } ``` @@ -935,14 +956,14 @@ db.collection('comments').doc('comment-id').update({ ``` // 更新前 { - _id: 'xxx', - users: ['a','b'] + "_id": "xxx", + "users": ["a","b"] } // 更新后 { - _id: 'xxx', - users: ['b'] + "_id": "xxx", + "users": ["b"] } ```