Collection.field / Query.field / Document.field

指定返回结果中记录需返回的字段

方法签名如下:

  1. function field(definition: object): Collection | Query | Document

方法接受一个必填字段用于指定需返回的字段

示例代码

返回 description, done 和 progress 三个字段:

  1. const cloud = require('wx-server-sdk')
  2. cloud.init()
  3. const db = cloud.database()
  4. exports.main = async (event, context) => {
  5. try {
  6. return await db.collection('todos').field({
  7. description: true,
  8. done: true,
  9. progress: true
  10. }).get()
  11. } catch(e) {
  12. console.error(e)
  13. }
  14. }

原文: https://developers.weixin.qq.com/miniprogram/dev/wxcloud/reference-server-api/database/collection.field.html