新聞中心
這里有您想知道的互聯網營銷解決方案
創(chuàng)新互聯小程序教程:微信小程序云開發(fā)服務端數據庫API 統(tǒng)計集合記錄數
Collection.count / Query.count
統(tǒng)計集合記錄數或統(tǒng)計查詢語句對應的結果記錄數,云函數端因屬于管理端,因此可以統(tǒng)計所有集合的記錄數(小程序端統(tǒng)計會受限于權限,可見小程序端的 count)

函數簽名如下:
function count(): Promise
返回值說明
Promise 的 resolve 和 reject 的結果定義如下:
| 結果說明 | |
|---|---|
| resolve | 查詢的結果,Result 定義見下方 |
| reject | 失敗原因 |
Result 說明
resolve 的結果 Result 是一個如下結構的對象:
| 字段 | 類型 | 說明 |
|---|---|---|
| total | number | 結果數量 |
示例代碼
獲取我的待辦事項總數
Promise 風格
const cloud = require('wx-server-sdk')
cloud.init()
const db = cloud.database()
exports.main = async (event, context) => {
return await db.collection('todos').where({
_openid: 'xxx' // 填入當前用戶 openid
}).count()
} 網站欄目:創(chuàng)新互聯小程序教程:微信小程序云開發(fā)服務端數據庫API 統(tǒng)計集合記錄數
分享地址:http://m.fisionsoft.com.cn/article/dpjidoi.html


咨詢
建站咨詢
