Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
CoderSmallfan
uni-app
提交
05b1c298
U
uni-app
项目概览
CoderSmallfan
/
uni-app
与 Fork 源项目一致
Fork自
DCloud / uni-app
通知
1
Star
1
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
1
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
U
uni-app
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
1
Issue
1
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
05b1c298
编写于
10月 26, 2020
作者:
雪洛
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
docs: uniCloud clientDB jql
上级
431c5bd7
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
82 addition
and
19 deletion
+82
-19
docs/uniCloud/database.md
docs/uniCloud/database.md
+82
-19
未找到文件。
docs/uniCloud/database.md
浏览文件 @
05b1c298
...
...
@@ -370,6 +370,33 @@ db.collection('order,book') // 注意collection方法内需要传入所有用到
}).
catch
(
err
=>
{
console
.
error
(
err
)
})
// 上面的写法是clientDB的jql语法,如果不使用jql的话,写法会变得很长,大致如下
// 注意clientDB内联表查询需要用拼接子查询的方式(let+pipeline)
const
db
=
uniCloud
.
database
()
const
dbCmd
=
db
.
command
const
$
=
dbCmd
.
aggregate
db
.
collection
(
'
order
'
)
.
aggregate
()
.
lookup
({
from
:
'
book
'
,
let
:
{
book_id
:
'
$book_id
'
},
pipeline
:
$
.
pipeline
()
// 此match方法内的条件会和book表对应的权限规则进行校验,{status: 'OnSell'}会参与校验,整个expr方法转化成一个不与任何条件产生交集的特别表达式。这里如果将dbCmd.and换成dbCmd.or会校验不通过
.
match
(
dbCmd
.
expr
(
$
.
eq
([
'
$_id
'
,
'
$$book_id
'
])
))
.
done
()
as
:
'
book
'
})
.
match
({
book
:
{
title
:
'
三国演义
'
}
})
.
end
()
```
...
...
@@ -450,6 +477,18 @@ const db = uniCloud.database()
}).
catch
(
err
=>
{
console
.
error
(
err
)
})
// 上述写法等价于
const
db
=
uniCloud
.
database
()
db
.
collection
(
'
order
'
)
.
orderBy
(
'
quantity
'
,
'
asc
'
)
.
orderBy
(
'
create_date
'
,
'
desc
'
)
.
get
()
.
then
(
res
=>
{
console
.
log
(
res
);
}).
catch
(
err
=>
{
console
.
error
(
err
)
})
```
### 查询结果返回总数getcount@getcount
...
...
@@ -468,6 +507,23 @@ const db = uniCloud.database()
}).
catch
(
err
=>
{
console
.
error
(
err
)
})
// 如果不使用getCount,需要再调用一次count方法来返回总数
const
db
=
uniCloud
.
database
()
db
.
collection
(
'
order
'
)
.
get
()
.
then
(
res
=>
{
console
.
log
(
res
);
}).
catch
(
err
=>
{
console
.
error
(
err
)
})
db
.
collection
(
'
order
'
)
.
count
()
.
then
(
res
=>
{
console
.
log
(
res
);
}).
catch
(
err
=>
{
console
.
error
(
err
)
})
```
返回结果为
...
...
@@ -588,13 +644,17 @@ try {
| 字段 | 类型 | 必填 | 说明 |
| --------- | ------- | ---- | ------------------------ |
| deleted |
Integ
er | 否 | 删除的记录数量 |
| deleted |
Numb
er | 否 | 删除的记录数量 |
示例:判断删除成功或失败,打印删除的记录数量
```
js
const
db
=
uniCloud
.
database
();
db
.
collection
(
"
table1
"
).
doc
(
"
5f79fdb337d16d0001899566
"
).
remove
()
db
.
collection
(
"
table1
"
)
.
where
({
_id
:
"
5f79fdb337d16d0001899566
"
})
.
remove
()
.
then
((
res
)
=>
{
uni
.
showToast
({
title
:
'
删除成功
'
...
...
@@ -634,12 +694,13 @@ collection.doc().update(Object data)
```
js
const
db
=
uniCloud
.
database
();
let
collection
=
db
.
collection
(
"
table1
"
)
let
res
=
await
collection
.
doc
(
'
doc-id
'
).
update
({
name
:
"
Hey
"
,
count
:
{
fav
:
1
}
});
let
res
=
await
collection
.
where
({
_id
:
'
doc-id
'
})
.
update
({
name
:
"
Hey
"
,
count
:
{
fav
:
1
}
});
```
```
json
...
...
@@ -669,11 +730,12 @@ let res = await collection.doc('doc-id').update({
```
js
const
db
=
uniCloud
.
database
();
let
collection
=
db
.
collection
(
"
table1
"
)
let
res
=
await
collection
.
doc
(
'
doc-id
'
).
update
({
arr
:
{
1
:
"
uniCloud
"
}
})
let
res
=
await
collection
.
where
({
_id
:
'
doc-id
'
})
.
update
({
arr
:
{
1
:
"
uniCloud
"
}
})
```
```
json
...
...
@@ -703,12 +765,13 @@ let res = await collection.where("name=='hey'").update({
```
js
const
db
=
uniCloud
.
database
();
const
res
=
await
db
.
collection
(
'
table1
'
).
doc
(
'
1
'
).
update
({
// 更新students[1]
[
'
students.
'
+
1
]:
{
name
:
'
wang
'
}
})
const
res
=
await
db
.
collection
(
'
table1
'
).
where
({
_id
:
'
1
'
})
.
update
({
// 更新students[1]
[
'
students.
'
+
1
]:
{
name
:
'
wang
'
}
})
```
```
json
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录