后浪云小程序教程:微信小程序云开发服务端数据库API 指定返回结果中记录需返回的字段
Collection.field / Query.field / Document.field
指定返回结果中记录需返回的字段
方法签名如下:
function field(definition: object): Collection | Query | Document
方法接受一个必填字段用于指定需返回的字段
示例代码
返回 description, done 和 progress 三个字段:
const cloud = require('wx-server-sdk')
cloud.init()
const db = cloud.database()
exports.main = async (event, context) => {
try {
return await db.collection('todos').field({
description: true,
done: true,
progress: true
}).get()
} catch(e) {
console.error(e)
}
}
版权声明:
作者:后浪云
链接:https://www.idc.net/help/185050/
文章版权归作者所有,未经允许请勿转载。
THE END